Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

XMLPort Export

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

I want to export some items from datatable and i have followed this guide which is super nice.

How can i modify the xml tag so instead of the following 

<Root>
<SaleHeader>
<No.>1002</No.>
<Name>Foooffice ApS</Name>
<Address>Foolandsvej</Address>
<City>Svendborg</City>

I can put the xml tag as followed:

<val n="name">Foooffice ApS</val>
<val n="address1">Foolandsvej</val>
<val n="city">Svendborg</val>

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: XMLPort Export

    For silent download to a folder on the client side i changed 

    DOWNLOAD(FromFile,'Download file','c:\','TXT file(*.txt)|*.txt',ToFile);


    out with this

    FileMgt.DownloadToFile(FromFile,'C:\Users\Administrator\Desktop\PacSoft\'+ FORMAT(SalesHeader."No.") + '.txt');

    So now it saves the file on the clients PC silent (with dialog box)

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: XMLPort Export

    I enden up with this solution which i think is easy to change the xml if needed.

    SalesHeader.SETRANGE("No.","No.");
    SalesHeader.FIND('-');
    
    outFile.CREATE('c:\OutFile.txt');
    outFile.CREATEOUTSTREAM(outStream);
    streamWriter := streamWriter.StreamWriter(outStream, encoding.Unicode);
    ToFile := FORMAT(SalesHeader."No.") + '.txt';
    FromFile := outFile.NAME;
    
    txtCRLF := 'xx';
    txtTAB := 'x';
    txtCRLF[1] := 13;
    txtCRLF[2] := 10;
    txtTAB[1] := 9;
    
    SourceText :='<?xml version="1.0" encoding="ISO-8859-1"?>' + txtCRLF +
          '<pacsoft>' + txtCRLF +      
          '<shipment orderno="'+ SalesHeader."No." +'">' + txtCRLF +
          '<val n="from">' +'1' + '</val>' + txtCRLF +
          '<val n="to">' + SalesHeader."Bill-to Customer No." + '</val>' + txtCRLF +
          '<val n="reference">' + SalesHeader."No." + '</val>' + txtCRLF +
          '<val n="termcode"></val>' + txtCRLF +
          '<service srvid="PDKEP">' + txtCRLF +
          '</service>' + txtCRLF +
          '<container type="parcel">' + txtCRLF +
          '<val n="copies">' + FORMAT(SalesHeader."Pac Qty") + '</val>' + txtCRLF +
          '<val n="weight">' + FORMAT(SalesHeader."Pac weight") + '</val>' + txtCRLF +
          '<val n="contents">' + SalesHeader."Pac content" + '</val>' + txtCRLF +
          '<val n="packagecode">PC</val>' + txtCRLF +
          '</container>' + txtCRLF +
          '</shipment>' + txtCRLF +
          '<receiver rcvid="' + SalesHeader."Bill-to Customer No." + '">' + txtCRLF +
          '<val n="name"><![CDATA['+ SalesHeader."Ship-to Name" +']]></val>' + txtCRLF +
          '<val n="address1"><![CDATA[' + SalesHeader."Ship-to Address" +']]></val>' + txtCRLF +
          '<val n="address2"><![CDATA[' + SalesHeader."Ship-to Address 2" +']]></val>' + txtCRLF +
          '<val n="zipcode">' + SalesHeader."Ship-to Post Code" + '</val>' + txtCRLF +
          '<val n="city"><![CDATA[' + SalesHeader."Ship-to City" + ']]></val>' + txtCRLF +
          '<val n="country">' + SalesHeader."Ship-to Country/Region Code" + '</val>' + txtCRLF +
          '<val n="email">' + SalesHeader."Sell-to Contact E-Mail" + '</val>' + txtCRLF +
          '<val n="contact"><![CDATA[' + SalesHeader."Ship-to Contact"  +']]></val>' + txtCRLF +
          '</receiver>' + txtCRLF +
          '</pacsoft>';
    
    streamWriter.WriteLine(SourceText);
    
    streamWriter.Close();
    outFile.CLOSE();
    
    DOWNLOAD(FromFile,'Download file','c:\','TXT file(*.txt)|*.txt',ToFile);
    
    ERASE(FromFile);
    

    However i have a related question, If i want to save the file to a folder on Desktop called PacSoft C:\Users\Administrator\Desktop\PacSoft, I know its not the best path but just as an example, how do i do this? I have tried changeing the path on line no. 4 in the code but i get an error when i try use the function.

  • keoma Profile Picture
    keoma 32,675 on at
    RE: XMLPort Export

    that's very straight forward, but sounds good for me.

    only some suggestions. repeat until should not be necessary, sales header recs by no. (prim. key) should be unique. also setrange and find at the beginning are not necessary, because the sales header rec is given in the param of onrun, so salesheader var. could be replaced by rec. until purchline.next = 0 seems to be an error.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: XMLPort Export

    Hi Archer, I think that look very complicated.

    What if i did it this way since XMLPort dosn't work for my xml export task.

    OnRun(VAR Rec : Record "Sales Header")
    
    SalesHeader.SETRANGE("No.",SalesHeader."No.");
    SalesHeader.FIND('-');

    outFile.CREATE('c:\OutFile.xml'); outFile.CREATEOUTSTREAM(outStream); streamWriter := streamWriter.StreamWriter(outStream, encoding.Unicode); ToFile := FORMAT(SalesHeader."No.") + '.xml'; FromFile := outFile.NAME; REPEAT SourceText :='<?xml version="1.0" encoding="ISO-8859-1"?>' + '<data>' + '<shipment orderno="'+ SalesHeader."No." +'">' + '<val n="from">' +'1' + '</val>' + '<val n="to">' + SalesHeader."Bill-to Customer No." + '</val>' + '<val n="reference">' + SalesHeader."No." + '</val>' + '<val n="termcode"></val>' + '<service srvid="PDKEP">' + '</service>' + '<container type="parcel">' + '<val n="copies">' + 'FORMAT(SalesHeader."Packaging Label Qty")' + '</val>' + //'<val n="weight"></val>' + '<val n="packagecode">PC</val>' + '</container>' + '</shipment>' + '<receiver rcvid="' + SalesHeader."Bill-to Customer No." + '">' + '<val n="name"><![CDATA['+ SalesHeader."Ship-to Name" +']]></val>' + '<val n="address1"><![CDATA[' + SalesHeader."Ship-to Address" +']]></val>' + '<val n="address2"><![CDATA[' + SalesHeader."Ship-to Address 2" +']]></val>' + '<val n="zipcode">' + SalesHeader."Ship-to Post Code" + '</val>' + '<val n="city"><![CDATA[' + SalesHeader."Ship-to City" + ']]></val>' + '<val n="country">' + SalesHeader."Ship-to Country/Region Code" + '</val>' + '<val n="email">' + SalesHeader."Sell-to Contact E-Mail" + '</val>' + '<val n="contact"><![CDATA[' + SalesHeader."Ship-to Contact" +']]></val>' + '</receiver>' + '</data>'; streamWriter.WriteLine(SourceText); UNTIL PurchaseLine.NEXT = 0; streamWriter.Close(); outFile.CLOSE(); DOWNLOAD(FromFile,'Download file','c:\','XML file(*.xml)|*.xml',ToFile); ERASE(FromFile);
  • Suggested answer
    keoma Profile Picture
    keoma 32,675 on at
    RE: XMLPort Export

    that's not possible with xmlports.

    for complex xml handling like that use cu 6224 and follow 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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans