amorlzu / pugixml

Automatically exported from code.google.com/p/pugixml
0 stars 0 forks source link

strange characters in attribute val #220

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

I'm parsing an xml file and retrieving a value from it using an xpath 
expression:
std::string val = doc.select_single_node("xpath 
expression").node().child_value();

and then rewriting it as an attribute in a new xml document:

newxml.append_attribute(val.c_str());

What is the expected output? What do you see instead?

value of val expected (1,8361); Val printed out using std::cout
Instead I get "
1,8361" in the newxml file attribute

Which version of pugixml are you using? On what operating system/compiler?

Using g++ with pugixml 1.2

Please provide any additional information below.

Original issue reported on code.google.com by hepplewh...@gmail.com on 14 Dec 2013 at 8:11

GoogleCodeExporter commented 9 years ago
This character is an XML encoding of a newline (\n).
It is there because pugixml treats PCDATA whitespace as significant; to fix 
this you'll have to trim the string that you get from child_value.

There used to be a parsing option that did this for all PCDATA elements; it may 
be reimplemented again in the future, but for now manual trimming is the only 
solution.

Original comment by arseny.k...@gmail.com on 15 Dec 2013 at 1:13

GoogleCodeExporter commented 9 years ago
Hi,

I've tried trimming the string but I can't seem to delete the chars.

Using:
val.erase(0,5) results in deleting the actual data I want. It seems that the 
data exists within the string (as revealed by std::cout) but cannot be accessed 
in the string.

Original comment by hepplewh...@gmail.com on 15 Dec 2013 at 2:05

GoogleCodeExporter commented 9 years ago
Ah. Got it sorted. Thanks.

Original comment by hepplewh...@gmail.com on 15 Dec 2013 at 4:13

GoogleCodeExporter commented 9 years ago

Original comment by arseny.k...@gmail.com on 20 Dec 2013 at 5:49

GoogleCodeExporter commented 9 years ago

Original comment by arseny.k...@gmail.com on 15 Jan 2014 at 4:46