Re: [xml] xmlNodeGetContent and xmlNodeSetContent



Hi Lazlo

- xmlNodeGetContent retrieves the sub-element-nodes' text values too
- xmlNodeSetContent drops the whole subtree replacing with the new text value

This is actually the correct behaviour, and all parsers work this way. The content of an element is ALL the 
text nodes contained by that element - this includes the text nodes contained by its children. Therefore 
replacing the content will remove all child nodes.

It is this way because an element can contain multiple text nodes, interspersed with other elements, such as:

<element1>
some content <element2> element 2s content</element2
some more content
</element1>

the content of element1 is said to be:
some content element 2s content some more content

If you wish to replace parts of the content (in other words you wish to replace specific TEXT nodes), you 
need to locate the specific text node you are interested in (checking child nodes of element1 to see if they 
are of type=="text").

Hope this makes sense?

Cheers

Mike
http://www.mikekneller.com



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