Loop XML with namespace is not working
Posted: Tue May 04, 2021 12:48 pm
I have this XML with namespace and I want to get e.g all the numbers in the Number tag. But the loop is not working with the namespace. I need to use a loop like this because I'am doing other stuff as well in the loop.
I have this code. I have comment out some code when I try to parse the XML with the namespace but it's not working. I don't need to use the namespace I just need to parse/loop the XML.
If I remove the namespace my code works fine. But I will get the XML with namespace.
I can I change my code to make it work with the first XML with namespace?
Code: Select all
<xx.yy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xx.se/schemas/xx.yy/3.0/integration IntegrationDocumentSchema.xsd" xmlns="http://xx.se/schemas/xx.yy/3.0/integration">
<Envelope>
<Client>Cusomer</Client>
</Envelope>
<Data>
<Item>
<Number>11111</Number>
<Balance>2</Balance>
</Item>
<Item>
<Number>2222</Number>
<Balance>4</Balance>
</Item>
</Data>
</xx.yy>
Code: Select all
function jobArrived( s : Switch, job : Job )
{
var path = s.getSpecialFolderPath("PluginResources");
var companyXML = File.toNativeSeparators(path + "/myXML.xml");
var selectedNode;
var company = new Document(companyXML);
//var companyns = company.createDefaultMap();
var companyItems = company.evalToNodes("/xx.yy/Data/Item", null);
//var companyItems = company.evalToNodes("/xx.yy/Data/Item", companyns);
for (var i = 0; i < companyItems.length; i++) {
s.log(1, "Loop working");
}
}
Code: Select all
<xx>
<Envelope>
<Client>Cusomer</Client>
</Envelope>
<Data>
<Item>
<Number>11111</Number>
<Balance>2</Balance>
</Item>
<Item>
<Number>2222</Number>
<Balance>4</Balance>
</Item>
</Data>
</xx>