XmlDocument_SelectNodes does not work with default namespace in the node

Hi there,

If I have some complex XML. The simplified XML looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<npsLk01>
<stuurgegevens>
<berichtcode>Lk01</berichtcode>
<zender>
<organisatie>3003</organisatie>
<applicatie>EXX</applicatie>
</zender>
<ontvanger>
<organisatie>3003</organisatie>
<applicatie>BELASTING</applicatie>
</ontvanger>
<referentienummer>1846337</referentienummer>
<tijdstipBericht>2019073114221706</tijdstipBericht>
<entiteittype>NPS</entiteittype>
</stuurgegevens>
</npsLk01>

and if I use XmlDocument_SelectNodes with XPathString set to "/npsLk01/stuurgegevens/berichtcode" I get an XmlNodeList_Count of 1.

The actual XML uses default namespaces all around and looks like (still simplified with addition in bold):

<npsLk01 xmlns="http://www.egem.nl/StUF/sector/bg/0310" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<stuurgegevens>
<berichtcode>Lk01</berichtcode>
<zender>
<organisatie>3003</organisatie>
<applicatie>EXX</applicatie>
</zender>
<ontvanger>
<organisatie>3003</organisatie>
<applicatie>BELASTING</applicatie>
</ontvanger>
<referentienummer>1846337</referentienummer>
<tijdstipBericht>2019073114221706</tijdstipBericht>
<entiteittype>NPS</entiteittype>
</stuurgegevens>
</npsLk01>

Because of the added namespaces, whatever I try in XPathString does not seem to come up with a XmlNodeList_Count.

Help is appreciated.

Saludos,

Wilko

Solution

Hi Wilko,


this is an Xpath feature, not an Outsystems one.  See this older post.  It is because of your default xmlns in the second xml example.

I have tried what they say there on your example xml, and following xpath string works on both

/*[local-name()='npsLk01']/*[local-name()='stuurgegevens']/*[local-name()='berichtcode']

see attached oml

good luck with it,

Dorine

Solution

Hi Dorine,

My first attempt to read the XML was with XmlToRecordList where you need to specify the structure, but with XmlToRecordList I had troubles with the namespaces used as prefixes, and also nodenames that have a . in the name.

Then I tried XmlDocument_Load with an XSD attached, but that went nowhere as other xsd's are called with hierarchies. XmlDocument_Load without an XSD looks to be the way, and thanks for the help.

Now I am basically stuck at selecting the nodes i am interested in (with XmlElement_SelectNodes) which are inside a node (with XmlNodeList_Item) from a list of nodes I selected with XmlDocument_SelectNodes. I try some more, if I get really stuck, hopefully i can bother you again.

Thanks,

Wilko