EDN Admin
Well-known member
http://dom4j.sourceforge.net/ dom4j (a really good Java XML library) has a very useful call. On the equivalent of their XPathNavigator object you can request a unique Xpath statement that will give you that specific node. We needed the same
thing in our .NET code so I wrote the equivalent.
Note: This requires that there is an XmlDocument underlying the XPathNavigator object. You can have an XPathNavigator object that is not wrapping an XmlDocument and for those cases, this will not work.
To call this, you pass in the XmlNode that the XPathNavigator object is presently on. That is contained in XPathNavigator.UnderlyingObject.
Also, if you explicitly set any namespaces you need to pass in a Dictionary<string,string> where the key is the namespace uri and the value is the prefix. The underlying XmlDocument will use the namespaces as defined in the original XML, not the namespaces
assigned to it after loading it (no idea why). You can pass null if you did not explicitly set any namespaces.
If you have any suggestions or see any bugs, please post a comment. Code at http://blogs.windwardreports.com/davidt/2010/12/xml-get-unique-xpath.html
XML Get Unique XPath
thanks to all here for the help on this - dave <hr class="sig Very funny video - http://blogs.windwardreports.com/davidt/2010/02/reporting-as-a-metaphor.html
Whats your Metaphor?
View the full article
thing in our .NET code so I wrote the equivalent.
Note: This requires that there is an XmlDocument underlying the XPathNavigator object. You can have an XPathNavigator object that is not wrapping an XmlDocument and for those cases, this will not work.
To call this, you pass in the XmlNode that the XPathNavigator object is presently on. That is contained in XPathNavigator.UnderlyingObject.
Also, if you explicitly set any namespaces you need to pass in a Dictionary<string,string> where the key is the namespace uri and the value is the prefix. The underlying XmlDocument will use the namespaces as defined in the original XML, not the namespaces
assigned to it after loading it (no idea why). You can pass null if you did not explicitly set any namespaces.
If you have any suggestions or see any bugs, please post a comment. Code at http://blogs.windwardreports.com/davidt/2010/12/xml-get-unique-xpath.html
XML Get Unique XPath
thanks to all here for the help on this - dave <hr class="sig Very funny video - http://blogs.windwardreports.com/davidt/2010/02/reporting-as-a-metaphor.html
Whats your Metaphor?
View the full article