Groups | Blog | Home
all groups > dotnet xml > february 2005 >

dotnet xml : Do XmlNode's have a unique internal system ID?


nntp1.sympatico.ca
2/19/2005 12:51:09 AM
Hello all,

Do System.Xml.XmlNode's have a unique system ID available via a
property somehow?

I have nodes which may be very similar or even identical (but in
different locations) in a document and need to be able to look them up
via this ID. I have for now assigned my own GUID to each node, and can
use XPATH to grab the node I need, but I'm sure the DOM objects must
have something internal I could use instead and be much more efficient.

Many thanks for any help - have a super evening!

Cheers,
Pascal Schmitt
2/19/2005 1:15:52 PM
Hello!

You can use XPath's generate-id() function which will return an unique
ID for a given node.

XmlDocument a = new XmlDocument();
a.Load("c:\foo.xml");
XmlDocument b = new XmlDocument();
b.Load("c:\foo.xml");

a.CreateNavigator().Evaluate("generate-id(/root/element[1])");
b.CreateNavigator().Evaluate("generate-id(/root/element[1])");

This will maybe not return the same value.


--
Pascal Schmitt
2/20/2005 3:28:43 PM
Hello!

[quoted text, click to view]

Oh, sorry :S

That's why I didn't find anything about it in the XPath Spec..., thanks.

--
Dimitre Novatchev
2/20/2005 6:20:15 PM

[quoted text, click to view]

The generate-id() function is only available to XPath in a context
established by XSLT. Trying to evaluate in a non-XSLT context an XPath
expression containing generate-id() results in an error, due to this
function not being recognised.

Cheers,
Dimitre Novatchev.

AddThis Social Bookmark Button