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 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

I have the same question (0)
  • Suggested answer
    keoma Profile Picture
    32,729 on at

    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

  • Community Member Profile Picture
    on at

    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
    Suresh Kulla Profile Picture
    50,247 Super User 2025 Season 2 on at

    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.

  • Community Member Profile Picture
    on at

    105.PNG

  • Verified answer
    Community Member Profile Picture
    on at

    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;

  • Verified answer
    Suresh Kulla Profile Picture
    50,247 Super User 2025 Season 2 on at

    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

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 NAV (Archived)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans