Is there a best practice for adding namespacing to xml output? I effectively need my output to look like this:
<ns0:Visit xmlns:ns0="
http://my.url">
<ns0:PatientFirstName>First</ns0:PatientFirstName>
<ns0:PatientLastName>Last</ns0:PatientLastName>
<ns0:InsurancePlans>
<ns0:InsurancePlan>
<ns0:PlanOrder>1</ns0:PlanOrder>
<ns0:Name>Medicaid</ns0:Name>
</ns0:InsurancePlan>
<ns0:InsurancePlan>
<ns0:PlanOrder>2</ns0:PlanOrder>
<ns0:Name>BlueCross</ns0:Name>
</ns0:InsurancePlan>
</ns0:InsurancePlans>
</ns0:Visit>
...but when i attempt to add child elements using setNode and include the "ns0:" I get errors. I've found that when I create my xml message I can give it a template that includes the namespacing, but in doing that i don't always know how many InsurancePlan elements I'll need to output--as such, my template only specs out one. when I try to do a message.addChild I run into issues again with setNode.
Here is my template:
<ns0:Visit xmlns:ns0="
http://my.url">
<ns0:PatientFirstName></ns0:PatientFirstName>
<ns0:PatientLastName></ns0:PatientLastName>
<ns0:InsurancePlans>
<ns0:InsurancePlan>
<ns0:PlanOrder></ns0:PlanOrder>
<ns0:Name></ns0:Name>
</ns0:InsurancePlan>
</ns0:InsurancePlans>
</ns0:Visit>
...and here is some brief sample code
message = qie.createXMLMessage(qie.getVariable('XmlTemplate'), "UTF-16");
message.setNode("/Visit/PatientFirstName", source.getNode("/patient/firstName"));
message.setNode("/Visit/PatientLastName", source.getNode("/patient/lastName"));
message.setNode("/Visit/InsurancePlans", "InsurancePlan", 1, true);
var insCount = source.getCount("/insurance");
var insObject = qie.parseJSONString(source.getNode("/insurance"));
for (var insCounter = 1; insCounter <= insCount; insCounter++) {
var insRoot = "/[" + insCounter + "]";
var insuranceName = insObject.getNode(insRoot + "/name");
if (StringUtils.length(insuranceName) > 0) {
message.addChild("/Visit/InsurancePlans", "InsurancePlan", "");
var msgInsRoot = "/Visit/InsurancePlans/InsurancePlan[" + insCounter.toString() + "]";
if (insCounter === 1)
{
msgInsRoot = "/Visit/InsurancePlans/InsurancePlan";
}
message.setNode(msgInsRoot + "/PlanOrder", insObject.getNode(insRoot + "/position"));
message.setNode(msgInsRoot + "/Name", insuranceName);
}
}
When I do it that way my second InsurancePlan values end up without the namespacing (though my first ones get it)