web
You’re offline. This is a read only version of the page.
close
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 737

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

I have the same question (0)
  • Mea_ Profile Picture
    60,284 on at

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

  • B K Sharma Profile Picture
    737 on at

    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

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    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.

  • Blue Wang Profile Picture
    on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans