I am trying to loop through some XML and set the value of a string to be equal to a particular nodes contents. The XML looks like:
<RootNode>
<SubNode>test<SubNode>
<SubNode><ExtraMarkup>some value</ExtraMarkup><SubNode>
</RootNode>
Where each sub node can either contain a value or additional XML child nodes. For the first subnode this code works correctly:
for Node := 0 to RootNode.childNodes.length-1 do begin
AttrValue := RootNode.childNodes[Node].selectSingleNode('SubNode').Text;
// More code here...
end;
The problem is when the subnode contains child nodes. I would like the value of AttrValue to be ‘test‘ or ‘<ExtraMarkup>some value</ExtraMarkup>‘ as a string.
If instead of text I get the XML attribute the markup is not preserved.
1 Answer