18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Reading xml file with namespaces

wgoriswgoris Members
edited November -1 in Sahi - Open Source
Hello,

Our application generates xml files and I want to check the content to see if it is generated correctly. However I have troubles when the namespace is present in the tags.

Example xml:
<ns3:Repliek xmlns:ns2="http://v1.geeforganisatie.organisatie.verzoek.dienst.milieuinfo.be" xmlns:ns3="http://v1.geeforganisatie.organisatie.repliek.dienst.milieuinfo.be">
 <ns3:Context>
    <Taal>nl</Taal>
 </ns3:Context>
 <ns3:Antwoord>
    <ns3:ResponseIdentificatie>
       <Afzender>IMJV</Afzender>
       <Referte naam="001">02</Referte>
       <DatumTijd>2011-09-22T09:16:12.104+02:00</DatumTijd>
    </ns3:ResponseIdentificatie>
    <ns3:ResponseResultaat bron="vKBO">
       <Resultaat>Succes</Resultaat>
       <Omschrijving>Bron V_KBO werd succesvol bevraagd</Omschrijving>
    </ns3:ResponseResultaat>
    <ns3:ResponseResultaat bron="CBB">
       <Resultaat>Fout</Resultaat>
       <Omschrijving>Bron CBB werd niet succesvol bevraagd</Omschrijving>
    </ns3:ResponseResultaat>
    <ns3:Organisaties/>
 </ns3:Antwoord>
 <ns3:Berichten/>
</ns3:Repliek>

Sahi code:
var $xml = new XML(xmlStr);
var $string = $xml..ResponseResultaat.(@bron=="vKBO").Resultaat.toString();
_alert($string);

This returns "" but I want to get the value "Success".

When I remove the namespaces in all the tags:
<Repliek>
 <Context>
    <Taal>nl</Taal>
 </Context>
 <Antwoord>
    <ResponseIdentificatie>
       <Afzender>IMJV</Afzender>
       <Referte naam="001">02</Referte>
       <DatumTijd>2011-09-22T09:16:12.104+02:00</DatumTijd>
    </ResponseIdentificatie>
    <ResponseResultaat bron="vKBO">
       <Resultaat>Succes</Resultaat>
       <Omschrijving>Bron V_KBO werd succesvol bevraagd</Omschrijving>
    </ResponseResultaat>
    <ResponseResultaat bron="CBB">
       <Resultaat>Succes</Resultaat>
       <Omschrijving>Bron CBB werd succesvol bevraagd</Omschrijving>
    </ResponseResultaat>
    <Organisaties/>
 </Antwoord>
 <Berichten/>
</Repliek>

The same piece of sahi code gives as result "Success".

So my question is: how can I retrieve the correct expected result when there are namespaces in the xml tags?

Thank you in advance.
Best regards!
Sign In or Register to comment.