Search code examples
microsoft-dynamicsdynamics-ax-2012xml-attribute

Adding attributes to xmlNode in Axapta 2012


Can we add attributes to xmlNode in Axapta 2012? If so, how do I do this?

Below is my XML. I need to add an Id attribute to the <Task> node.

<Task Id="Cs-2213">
    <Name>Cannot delete the picking lists (lines)</Name>
    <Version>6.2.1000.4051</Version>
    <Sprint>17.8</Sprint>
    <Project>Cs2213_Prd_DelPickIssue</Project>
    <Area>Production</Area>
    <Status>Closed</Status>
    <BugTrackId/>
</Task>

Solution

  • You can use the XmlElement.setAttribute method to add attributes to an XML node. So for example if xmlElement is the Task XML node, the code would be

    xmlElement.setAttribute('Id', 'Cs-2213');
    

    See also XmlElement.setAttribute Method [AX 2012] (MSDN documentation of the method) and Create XML and write to file in Dynamics AX (complete example and first Google result for "dynamics ax xml attributes")