The XML standard defines an attribute 'space' used to define how whitespace is treated for current node and all below. See http://www.w3.org/TR/REC-xml/#sec-white-space
If an element contains no text, but whitespace only, TinyXml skips the whitespace. The following suggestion will create a text node containing the whitespace. Changes in TiXmlElement::ReadValue()
// We hit a '<'
// Have we hit a new element or an end tag? This could also be
// a TiXmlText in the "CDATA" style.
if ( StringEqual( p, "</", false, encoding ) )
{
// If whitespace exists, add a text node containing whitespace
if ( !TiXmlBase::IsWhiteSpaceCondensed() )
{
if (p != pWithWhiteSpace)
{
TiXmlText* textNode = new TiXmlText( "" );
p = textNode->Parse( pWithWhiteSpace, data, encoding );
LinkEndChild( textNode );
}
}
return p;
}
Patch worked for me, thanks.
Small addition: For elements that contain e.g. a CR or LF character first this still fails as the initial SkipWhitespace will NOT skip "
 ", however the GetChar() called when parsing transforms this back to '\n' and therefore Blank() later returns TRUE and the TextNode is not linked.
I solved it by changing the code of Blank() as follows:
bool TiXmlText::Blank() const
{
if ( !TiXmlBase::IsWhiteSpaceCondensed() )
{
return value.length() == 0;
}
else
{
for ( unsigned i=0; i<value.length(); i++ )
if ( !IsWhiteSpace( value[i] ) )
return false;
return true;
}
}
Hello!
I am trying to build an xml message where some tags need to have a value that includes CR LF chars.
I have made the patch change in ReadValue function and I have the following:
<mytest>
<mytag>this is line 1 this is line 2</mytag>
</mytest>
The \r\n characters within the tag value are transformed into , while they exist at the end of each line above.
I have also tried to add these characters in the tag value as follows:
"\r\n"
" "
"0x0D0x0A"
" "
No success so far!
I also added the second patch proposed here, still same result.
Any help would be greatly appreciated!
Thank you!