I have the following XML:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<MessageRequest></MessageRequest>
</SOAP-ENV:Envelope>
I am accessing the name of the child element like this:
childNode(SOAP-ENV:Body").ChildNodes(0).Name, but if there is a space between elements, the child node name returns "\n ", but if I remove the space I get the correct child node, for example, if there is a space between <SOAP-ENV:Body> and <MessageRequest>, the first child will return "\n ", but if there is no space, it will return <MessageRequest>
You are not mentioning the language you are using, but based on your profile, the name of the
ChildNodesproperty and indexing with round brackets instead of square brackets, I think VB.NET?This situation can happen if you are using a document that preserves white space. A DOM parser works at a node level. Each component of the XML is a node. You can have a text node, a CDATA node, an element node etc. These will get picked up by the
ChildNodesproperty and the number of children will vary.Check the node types of the nodes you are working with.
If you have indented elements then that indentation (spaces, line feed etc) becomes the first child. Remove formatting and the first child should be an element child.