I'm using C# and I'm stumped. Does it just not support id()? I have a large XML file, about 4-5 of them at ~400kb, so I need some speed and performance wherever I can get it.
I use XmlDocument.SelectSingleNode("id('blahblahblah')") and it doesn't get the node by id. Am I going crazy or is it that C# XPath just doesn't support id()?
Use XmlDocument.GetElementById to get the XmlElement with the specified ID, e.g.:
XmlElement elem = doc.GetElementById("blahblahblah");
This works only with documents specifying a DTD though:
Attributes with the name "ID" are not of type ID unless so defined in the DTD.
In case your document does not have a DTD, you could use an XPath expression to select the node with the id attribute set to your ID:
XmlElement elem = doc.SelectSingleNode("//*[@id='blahblahblah']");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With