Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Reading XML Docs

(0) ShareShare
ReportReport
Posted on by

I need to read an XML Document to retrieve an element from it.  In my case I need to get the Identifier from an xml doc. Here's my current code, how can I Then find this data? 


recManufacturingSetup.FINDFIRST;
objFiles.RESET;
IF 1 = 1 THEN;
objFiles.SETFILTER(Path, '%1', recManufacturingSetup.AegisFolderPackoutRoot);
objFiles.SETFILTER(Name, '@*xml');
objFiles.SETRANGE("Is a file", TRUE);
IF objFiles.FINDSET(FALSE, FALSE) THEN REPEAT
recAegisPackoutImport.Filename := objFiles.Name;
IF recAegisPackoutImport.FINDLAST THEN
recAegisPackoutImport."Line No." := recAegisPackoutImport."Line No." + 1
ELSE
recAegisPackoutImport."Line No." := 1;
recAegisPackoutImport.INSERT;
UNTIL objFiles.NEXT = 0;
//Get file names from table and remove end tags
IF recAegisPackoutImport.FINDSET THEN REPEAT
PackoutFileName :=
COPYSTR(recAegisPackoutImport.Filename,1,12);
//Check Whse Serial Batch List for existing Serial No.
whseSerialBatchList.RESET;
whseSerialBatchList.SETRANGE("No.", PackoutFileName);
IF whseSerialBatchList.FINDFIRST THEN BEGIN
CLEAR(xmlDoc);
xmlDoc := xmlDoc.XmlDocument();
xmlDoc.Load(recAegispackoutImport."Folder Path" + recAegisPackoutImport.Filename);
xmlRoot := xmlDoc.DocumentElement();

xmlNodeListPackoutData := xmlDoc.GetElementsByTagName('PackoutBox'); //lew
xmlNodePackoutData := xmlNodeListPackoutData.Item(intNode);
xmlDoc.ReadNode(XmlReader reader)
END;
UNTIL recAegisPackoutImport.NEXT =0;

104.PNG

*This post is locked for comments

  • Verified answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,656 on at
    RE: Reading XML Docs

    Use the xmlNodeList to find the InventoryItems then loop each xmlNode of the xmlNodeList and then use teh function GetAttributeValue from the xmlDomManagement.

    blogs.msdn.microsoft.com/.../sample-of-how-to-read-a-simple-xml-document-using-msxml-dom-in-nav

  • Verified answer
    RE: Reading XML Docs

    Here is my current soloution, The only issue with this is it isn't finding the value within the <Identifier>. Any suggestions?

    recManufacturingSetup.FINDFIRST;

    objFiles.RESET;

    objFiles.SETFILTER(Path, '%1', recManufacturingSetup.AegisFolderPackoutRoot);

    objFiles.SETFILTER(Name, '@*xml');

    objFiles.SETRANGE("Is a file", TRUE);

    IF objFiles.FINDSET(FALSE, FALSE) THEN REPEAT

      recAegisPackoutImport."Folder Path" := objFiles.Path;

      recAegisPackoutImport.Filename := objFiles.Name;

    IF recAegisPackoutImport.FINDLAST THEN

     recAegisPackoutImport."Line No." := recAegisPackoutImport."Line No." + 1

    ELSE

     recAegisPackoutImport."Line No." := 1;

     recAegisPackoutImport.INSERT;

    UNTIL objFiles.NEXT = 0;

    //Get file names from table and remove end tags

    IF recAegisPackoutImport.FINDSET THEN REPEAT

     PackoutFileName :=

       COPYSTR(recAegisPackoutImport.Filename,1,12);

       //Check Whse Serial Batch List for existing Serial No.

       whseSerialBatchList.RESET;

       whseSerialBatchList.SETRANGE("No.", PackoutFileName);

       IF NOT whseSerialBatchList.FINDFIRST THEN BEGIN

        whseSerialBatchList."No." := PackoutFileName;

        whseSerialBatchList.Insert;

         //Read XML Doc and Find Identifier.

         CLEAR(xmlDoc);

         xmlDoc := xmlDoc.XmlDocument();

         xmlDoc.Load(recAegisPackoutImport."Folder Path" + recAegisPackoutImport.Filename);

         xmlRoot := xmlDoc.DocumentElement();

         xmlNodeListPackoutData := xmlDoc.GetElementsByTagName('InventoryItem');         //ll

         xmlNodePackoutData := xmlNodeListPackoutData.Item(intNode);

         //Find the Value Within Identifier

         FOR intNodeBatch := 0 TO xmlNodeListpackoutData.Count() -1 DO BEGIN

           SerialNoText :=

             cuXMLDOMManagement.FindNodeText(

             xmlNodePackoutData,

             'Identifier');

           //Add Batch No to Serial No Information

           recSerialNoInformation.RESET;

           recSerialNoInformation.SETRANGE("Serial No.", SerialNoText);

           IF recSerialNoInformation.FINDFIRST THEN BEGIN

             recSerialNoInformation."Batch No." := PackoutFileName;

             recSerialNoInformation.MODIFY;

             CLEAR(SerialNotext);

           END;

         END;

       END;

       CLEAR(PackoutFileName);

    UNTIL recAegisPackoutImport.NEXT =0;

  • RE: Reading XML Docs

    105.PNG

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,656 on at
    RE: Reading XML Docs

    hello,

    can you highlight in the above xml document what value you are trying to retrieve, i have not found anything called PackOutBox which you have used in the above code.

  • RE: Reading XML Docs

    Im new to this whole codeunit etc, In the example above what would I use to find both the Identifiers in that XML Doc? I'm struggling with this

  • Suggested answer
    keoma Profile Picture
    keoma 32,675 on at
    RE: Reading XML Docs

    please have a look at cu 6224 xml mgmt.

    also check out my blog posting moxie4nav.wordpress.com/.../extend-cu-6224-read-xml-node-values-and-attributes

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

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,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans