Is it just me, or are XML namespaces really really that ugly to work with in .NET?
After formalizing my XML format and defining a schema, my cuddly-puppy code:
has suddenly turned into a scaly green fire-breathing monster:
xmlData.LoadXml(XmlString)Dim xmlGdiNamespaceManager As XmlNamespaceManagerxmlGdiNamespaceManager = New XmlNamespaceManager(xmlData.NameTable)xmlGdiNamespaceManager.AddNamespace("ns1", "urn:MyNamespace1")xmlGdiNamespaceManager.AddNamespace("ns2", "urn:MyNamespace2")xmlCommandCollection = xmlData.SelectNodes("//ns1:CommandCollection/*", xmlGdiNamespaceManager)
... Note that I had to rewrite all my XPath queries even though the actual XML hadn't changed (ns1 is the default namespace and isn't prefixed inside the XML file). And the xmlGdiNamespaceManager object needs to be re-inited every single time I want to call a SelectNodes from a different source? ugh....