Search code examples
.netxmlxpathactivexobject

ActiveX XML DOM SetProperty in .NET XmlDocument-Object


I'm working on a translation of some old code in our company that used the XML DOM from ActiveXObject ('Microsoft XML, v6.0'.DOMCocument60) to the .NET XML Document (System.Xml.XmlDocument)

I'm not really familiar with the details of XML but here is what i can tell you (hope it helps)

I need to replace this sequence:

DOMIn.setProperty('SelectionNamespaces','xmlns:def="' + DOMIn.documentElement.namespaceURI + '"');
NodeList := DOMIn.selectNodes('//def:Parameters');
RootNode := NodeList.item(0);

It's used to process an XML file comming in by a WebService. DOMIn is the incomming XML Object. I hope the other variables are self explaining.

So what i figured out myself is that i have to set the "def" Namespace after we recieve the Object it to use XPath. But i don't know how that is done in .NET XmlDocument. It's actually only about the first line. The others should be fine as soon as I start the methods with capital letters.

Please don't wonder about the Synthax the language is called C/AL - very proprietary. But we can implement .Net DLLs now and that's what my current task is.

Can you help me out?


Solution

  • Use an XmlNamespaceManager e.g.

    NsMgr := New XmlNamespaceManager(DOMIn.NameTable)
    NsMgr.AddNamespace("def", DOMIn.DocumentElement.NamespaceURI)
    
    NodeList := DOMIn.SelectNodes("//def:Parameter", NsMgr)