web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Suggested Answer

Reading XML file data via x++ code

(0) ShareShare
ReportReport
Posted on by

Hi All,

I am trying to read XML data via x++ Code. I have wrote a job which has no errors but still not able to fetch data.

Please Find my code below :

static void KTI_FindStorageId(Args _args)
{

XmlDocument doc = new XmlDocument();
XmlNodeList apiModelList;
XMLNode rootNode;
XmlNodeListIterator iterator;
XmlNodeList xmlResponseList;
XmlNodeList xmlTemplateList;
XmlElement apiModel;
XmlElement firstName;
XmlElement lastName;
XMLParseError xmlError;
str xmlMsg;
int i, j;


// Create the XML Document

doc.load("Purchase.xml");
apiModelList = doc.getElementsByTagName('storageId');
//doc = doc.selectSingleNode('storageId');

iterator= new XmlNodeListIterator(apiModelList);

while (iterator.moreValues())
{
apiModel = iterator.value();
firstName = apiModel.getNamedElement('storageId');

if (firstName)
{
info(strFmt("First Name: %1", firstName.text()));
}

iterator.nextValue();
}
}

/////////////////////////////////////////////////////

In above , I have highlighted a line in red.  Please let me know when I debug why it is not assigning any value to XML Element (firstName) in this case.

what is going wrong please let me know

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    I would suspect the structure of the XML is not in the way you are trying to process it, like it has special attributes or namespaces.

    Have a look at examples where they provide the document itself and read it from code, and compare it against yours.

    Such as:

    donatas.xyz/read-xml-string.html

    community.dynamics.com/.../ax-2012-reading-xml-nodes-under-specific-tag-through-x

    Pasting the XML header and the piece which you cannot read would also reveal what you are doing incorrectly.

    Also did you verify that your XML has been loaded correctly? I do not see any path information provided, maybe that is your problem.

  • Community Member Profile Picture
    on at

    Hi vilmos,

    Thanks for the Quick Reply.  in the code there is line "doc.load("Purchase.xml") which is the path for the file.

    however I am looking at your suggestions

  • Community Member Profile Picture
    on at

    Vilmos,

    Only problem with the line here is "firstName = apiModel.getNamedElement('storageId');"

    while debugging I have noticed that firstName is null.

    when put cursor over apiModel I could see the value which held between the tag <storageId>

    .

    what could be the problem ?

  • Vilmos Kintera Profile Picture
    46,149 on at

    Paste the XML, and please use the Insert Code </> formatting tag in the Use rich formatting editing mode!

    Your code is hard to read and not well-formatted in your original post too due to not using the tag for code pasting...

  • Martin Dráb Profile Picture
    239,099 Most Valuable Professional on at

    It seems that apiModel already is the storageId element and your getNamedElement() is trying to get a nested storageId (which probably isn't there, therefore the function returns null).

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Basit Profile Picture

Basit 1

#1
GL-01081504-0 Profile Picture

GL-01081504-0 1

#1
Roya Profile Picture

Roya 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans