Friday, July 21, 2006

 

.NET XML Gotcha

Ran into another little wrinkle earlier in the week.

XMLNode.SelectNodes() and XMLNode.SelectSingleNode() are very handy methods inside the DOM for jumping around inside XML documents. However, don't try to alter the nodes that are returned because they may not be live.

It took me several hours to track down a bug in my code caused by this. I noticed that, although the OwnerDocument of the nodes returned was correct, when I walked back up the tree by following the parents, I bump into a null before reaching the document node.

Firstly, it amazes me to think that it must have taken effort to program it to be less useful. Secondly, I dislike the uncertainty of it all...

Quote from the Help:
The XmlNode should not be expected to be connected "live" to the XML document.
That is, changes that appear in the XML document may not appear in the XmlNode,
and vice versa.

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?