[xml] '&' char in text nodes



Hello,

 I'm a little bit confused, hope somebody can describe me this point.
Actually i'm using libxml2 indirectly (though PHP) but i was digging
some code too...

 So, i have simple XML document:

<?xml version="1.0"?><root/>

 I get root node and try to set textual content to it. In PHP it looks like:

$xml = domxml_open_mem('<'.'?xml version="1.0"?'.'><root/>');
$root = $xml->root();
$root->set_content('test');

 Internally PHP calls xmlNodeSetContentLen() for it and this function
calls xmlStringLenGetNodeList() to perform parsing of given text.
Everything works fine until i try to set following content:

test & test

 As you may see - there is '&' char in this text and libxml2 cuts
everything after this character (including it) instead of converting
it into &amp; as i expect so resulted document is:

<?xml version="1.0"?><root>test </root>

 instead of:

<?xml version="1.0"?><root>test &amp; test</root>

 It becames even more strange because all other special chars
('<','>','"') are converted into corresponding entites. I slso try to
perform same operation with Mozilla's DOM interface and it gives me
expected result.
 So the question is: is current behaviour is expected by design and i
should handle such charactes by myself or libxml2 is wrong in this
case?

PS: I have tested this with libxml2 v2.4.21

-- 
Best regards,
 Alexander                          mailto:flying dom natm ru





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]