Little xml:id spec finally got W3C Recommendation status. I believe XML programming would be better be xml:id done in 1998, not in 2005. Anyway. xml:id provides a mechanism for annotating elements with unique identifiers. You just set xml:id attribute for an element and you done, no need for DTD, XML Schema or anything else:
<catalog> <book xml:id="b101">...</book> <book xml:id="b102">...</book> <book xml:id="b102">...</book> </catalog>Having elements annotated with IDs you can query them (usually very fast and efficiently) by ID values using various XML API specific means - GetELementById() in DOM, id() function in XPath/XSLT/XQuery, XPathNavigator.MoveToId() etc.
I hope Microsoft XML Team would consider adding support for xml:id into the next .NET version and into XLinq. That's really valuable addition to the XML Core.
And of course I cannot avoid Canonical XML (C14N) and xml:id controversy. Read Norm for the crux of the issue. In short - Canonical XML is broken. Here is an illustration:
string xml = @" <foo xml:id=""f42"" xml:base=""http://foo.com""> <bar xml:base=""dir"">baz </foo>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlDsigC14NTransform c14n = new XmlDsigC14NTransform(); c14n.LoadInput(doc.SelectNodes("/foo/bar")); StreamReader sr = new StreamReader((Stream)c14n.GetOutput()); Console.WriteLine(sr.ReadToEnd());Guess what is the result?
<bar xml:base="dir" xml:id="f42"></bar>Not only xml:id is inherited by bar element (so now you can get different element when searching by the same ID), but xml:base is broken (absolute base URI part is lost). Too bad. Canonical XML should definitely be fixed.
Leave a comment