Adding multiple namespaces to xml root

Post Reply
msierra
Member
Posts: 22
Joined: Thu Nov 27, 2014 1:38 pm

Adding multiple namespaces to xml root

Post by msierra »

With legacy scripting, is it possible to add multiple namespaces to xml root?

For example;

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xmp="XMPieWSAPI">
<soap:Body>

</soap:Body>
</soap:Envelope>
cstevens
Member
Posts: 103
Joined: Tue Feb 12, 2013 8:42 pm

Re: Adding multiple namespaces to xml root

Post by cstevens »

Yes you can. Are you reading in that XML, or generating it from scratch?

It's been a while, but I believe you use createEmptyMap() function to create new namespaces, then any new elements you generate with createElement() should reference the appropriate namespace name you want to use.

If you're reading this in then I believe you use createDefaultMap() to pick the default namespace (i.e. soap), then createEmptyMap() for additional namespaces (i.e. xmp)
msierra
Member
Posts: 22
Joined: Thu Nov 27, 2014 1:38 pm

Re: Adding multiple namespaces to xml root

Post by msierra »

Thank you for answering. Currently I'm reading in a template xml file and using createDefaultMap(). Then I'm modifying element text with PrivateData values. It works as expected and achieved the desired end result.

evalToNode - the element to modify
createElement - to create new element for the current element requiring modification
createText - applying PrivateData values
appendChild - to append the previous created text to new element
replaceChild - to replace current with new.


Now I want to try and write from scratch. I'm attempting to fully replicate what is currently proven and used to successfully post requests.

I am trying to add additional namespaces to match the first I applied, xmlns:soap e.g. xmp="XMPieWSAPI" should be xmlns:xmp="XMPieWSAPI". Right now I cannot achieve this.


SCRIPT
function jobArrived( s : Switch, job : Job ){
var xmlPath = "C:\\\\...\\Campaign_GetID.xml"
var xmlDoc = new Document();
var xmlMap = xmlDoc.createEmptyMap();

xmlMap.put("soap", "http://schemas.xmlsoap.org/soap/envelope/");

var xmlRoot = xmlDoc.createElement("soap:Envelope",xmlMap);
xmlDoc.setDocumentElement(xmlRoot);

/*
xmlRoot.addAttribute('xsi', xmlMap, "http://www.w3.org/2001/XMLSchema-instance");
xmlRoot.addAttribute("xsd", xmlMap, "http://www.w3.org/2001/XMLSchema");
xmlRoot.addAttribute("xmp", xmlMap, "XMPieWSAPI");
var soapBody = xmlDoc.createElement("soap:Body",xmlMap);
xmlRoot.appendChild(soapBody);
var xmpRootElement = xmlDoc.createElement("xmp:GetID",xmlMap);
xmlRoot.appendChild(xmpRootElement);
*/

xmlDoc.save(xmlPath)

}


OUTPUT
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xsi="http://www.w3.org/2001/XMLSchema-instance" xsd="http://www.w3.org/2001/XMLSchema" xmp="XMPieWSAPI">
<soap:Body/>
</soap:Envelope>
Post Reply