Search code examples
xmlaxaptax++dynamics-ax-2012

How to add prefix to all root attributes xml in x++ ax 2012


I am trying to export information to xml in x++. I would like to have the end result look like this below. this is the root node. The issue is I don't get the pidx: prefix showing infront of all the attributes. For example if I have code like this

 xmlRoot = xmlDoc.createElement3(pidx, "Invoice", namespace);

it will produce the result

<pidx:Invoice xmlns:pidx="http://www.api.org/pidXML/v1.0"> 

which is fine but when i add attributes

xmlRoot.setAttribute("transactionPurposeIndicator","Original");

it leaves out the pidx: that is suppose to be infront of transactionPurposeIndicator thus not giving me the expected output below. Even if i add pidx: infront of the transactionPurposeIndicator it ignores it. How can i have it show for all attributes as this is the root node.

<?xml version="1.0" encoding="UTF-8"?> <pidx:Invoice pidx:transactionPurposeIndicator="Original" pidx:version="1.0" xmlns:pidx="http://www.api.org/pidXML/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.api.org/pidXML/v1.0 http://banff.digitaloilfield.com/XML/OI-PIDX-Invoice.xsd">  

Solution

  • Try xmlRoot.setAttribute2("transactionPurposeIndicator", namespace, "Original"); instead of xmlRoot.setAttribute("transactionPurposeIndicator","Original"); This will give the expected result.