Find xml-Node in a XML Doc containing Namespaces

ta5ta5 Member Posts: 1,164
Hi

Strange thing:
Using xmlmgt.findnode doesn't work if the document has a default namespace. Btw: xmlmgt = cu.6224

When I delete the namespace from the xml document with this function
https://mbs.microsoft.com/partnersource ... rvices.htm
it seems to work, but I'm quite puzzled why the namespace must be first removed.

Anybody encountered the same problem?

Thanks
Thomas

Answers

  • ta5ta5 Member Posts: 1,164
    Solved!!
    Before loading the xml document use the following statement:
    xmlDoc.setProperty('SelectionNamespaces','xmlns:myNamespace="http://www.foo.org/xmlns/foo-0001/1"');
    
    where myNamespace can be any word and the "http.."-part is the uri which was declared by the default name space.

    When using xpath queries in the findnode function, just prefix the path with the myNameSpace.
    Example:
    cText := xmlMgt.FindNodeText(CurrNode,'//myNamespace:statusCode');
    

    Hope this is helpful to somebody else.
    Thomas
Sign In or Register to comment.