Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to update and return XML file using X++

(0) ShareShare
ReportReport
Posted on by 735

Hi Experts,

I have to update a XML node value and need to return with new XML but using below approach I am unable to return new XML, Can you please help me to sort out this issue

void ReadAndUpdateFreightInXML(XML _xml)
{
XmlParseError xmlError;
XmlNode transactionNode;
XmlNodeList rateList;
XmlNode requestNode;
TMSRate localRate;
XmlDocument responseDoc1 = XmlDocument::newXml(_xml);
//xmlError = responseDoc.parseError();

try
{
//ttsbegin;
if (xmlError && xmlError.errorCode() != 0)
{
xmlError.reason();
}

transactionNode = responseDoc1.documentElement();

rateList = transactionNode.selectNodes(#request); //Request mote
requestNode = rateList.nextNode();

rateList = requestNode.selectNodes(#shipping);//ShippingEntity - 1
requestNode = rateList.nextNode();

rateList = requestNode.selectNodes(#shipping);//ShippingEntity - 2
requestNode = rateList.nextNode();

rateList = requestNode.selectNodes(#shipping);//ShippingEntity - 3
requestNode = rateList.nextNode();

rateList = requestNode.selectNodes(#ratings);//RAtingEntities -
requestNode = rateList.nextNode();

rateList = requestNode.selectNodes(#rating);//RAtingEntities -
requestNode = rateList.nextNode();
//Update price in #TotalRate Node
localRate = any2real(this.returnNamedNode(requestNode, #totalRate));
localRate += 11;
this.writeNode(requestNode,#totalrate, int642str(localRate));

rateList = requestNode.selectNodes(#rate);//RatingEntity -
requestNode = rateList.nextNode();
//Update price in #TotalRate Node
localRate = any2real(this.returnNamedNode(requestNode, #totalRate));
localRate += 11;
this.writeNode(requestNode,#totalrate, int642str(localRate+10));

//Update price in #UnitRate Node
localRate = any2real(this.returnNamedNode(requestNode, #UnitRate));
localRate += 11;
this.writeNode(requestNode,#unitrate, int642str(localRate+10));
//return responseDoc1;
}
catch
{
throw Exception::Error;
}
}

*This post is locked for comments

  • Blue Wang Profile Picture
    Blue Wang on at
    RE: How to update and return XML file using X++

    Hi BK,

    You can refer this blog: 

    https://mfmujahidmim.wordpress.com/2016/01/19/exporting-data-to-an-xml-file/

    XmlDocument xmlDoc;
    XMLWriter xmlWriter;
    xmlWriter = XMLWriter::newFile(@”C:\temp\test.xml”);
    xmlDoc.writeTo(xmlWriter);
    
    OR
    
    XmlDocument xmlDoc;
    #define.filename(@’C:\temp\test.xml’);
    xmlDoc.save(#filename);


    I  hope it will help you.

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: How to update and return XML file using X++

    You method accepts xml string and returns nothing. If you want to return new xml string then return it from the method and assign it to something or save it somewhere.

  • B K Sharma Profile Picture
    B K Sharma 735 on at
    RE: How to update and return XML file using X++

    Hi ievgen,

    I am able to update node value using mentioned approach but not able to return updated XML, IS there any way so that I can return final XML after node value update

    Thanks

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: How to update and return XML file using X++

    But you method does not return anything. So what is the issue?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,387 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans