Options

Remove heading on XMLport output?

Alex_ChowAlex_Chow Member Posts: 5,063
Is there a way to remove the heading from the XML export?

For example, how do I remove the
<?xml version="1.0" encoding="UTF-16" standalone="no" ?>
from the 1st line of the XMLport output?

Comments

  • Options
    ara3nara3n Member Posts: 9,256
    what is the reason for removing this?

    You need to load the xmlfile after xmlport has been run and remove it through xmldom

    Also notice that you are running it in UTF-16
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    Alex_ChowAlex_Chow Member Posts: 5,063
    This request was made by a vendor of one of our clients. I'm in the process of finding out why as well.

    What's wrong with UTF-16?
  • Options
    kinekine Member Posts: 12,562
    UTF-16 make sometime problems, all depends on how the XML is used...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    Alex_ChowAlex_Chow Member Posts: 5,063
    kine wrote:
    UTF-16 make sometime problems, all depends on how the XML is used...

    What kind of problems can we expect with UTF-16? Is it just general problems in the XML world? Or is it NAV specific?
  • Options
    ara3nara3n Member Posts: 9,256
    it's nav specific. If you are using message queue if I'm remembering correctly.

    As far as request take a look at this thread.

    viewtopic.php?f=23&t=31648&hilit=never+forget
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    Alex_ChowAlex_Chow Member Posts: 5,063
    The thread was on how to add the XML declaration. I'm trying to remove it.

    I don't think XMLport runs any codeunits when writing its output? I also don't find any property settings that removes the declaration line.
  • Options
    ara3nara3n Member Posts: 9,256
    you can't do it with xmlport. you need to do it afterward.

    you can pass a blank string to the function processingInstruction. Thus removing it. It doesn't hurt to try it.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    kinekine Member Posts: 12,562
    Or you can pass the XML into XMLDom and just remove the first node and you are done...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    Alex_ChowAlex_Chow Member Posts: 5,063
    kine wrote:
    Or you can pass the XML into XMLDom and just remove the first node and you are done...

    Whoa... This is getting over complicated to what was suppose to be an hour of work. I think I'll try to work with the vendor to see if they can accept the delcaration. It's suppose to be XML standard anyway.
  • Options
    DenSterDenSter Member Posts: 8,304
    I was going to say that it is part of well formed XML and should be accepted by any XML parser. Of course, namespaces are also part of wellformed XML and should also be accepted by XMLPorts, which they aren't...
  • Options
    KisuKisu Member Posts: 381
    kine wrote:
    Or you can pass the XML into XMLDom and just remove the first node and you are done...

    We have similar issue, that customers webservice does not accept the first line.

    I've port that exports xml file and I'm sending it to the webservice by automation,

    You say pass xml into XMLDom, how you remove first node? I'm not sure how to select it,.. this did not work fex:

    CREATE(XmlDoc);
    XmlDoc.async := FALSE;
    XmlDoc.load(Tiedosto); // <-- the xml file
    
    
    
    // This does not work???
    XmlNode := XmlDoc.selectSingleNode('XML');
    XmlDoc.removeChild(XmlNode);
    
    
    
    IF ISCLEAR(XmlHttp) THEN
      CREATE(XmlHttp);
    
    XmlHttp.open('POST', Url, FALSE);
    
    K.S.
  • Options
    kinekine Member Posts: 12,562
    lauXmlDom.load(Stream);
    
    lauXmlNode := lauXmlDom.firstChild;
    lauXmlDom.removeChild(lauXmlNode);
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    KisuKisu Member Posts: 381
    kine wrote:
    lauXmlDom.load(Stream);
    
    lauXmlNode := lauXmlDom.firstChild;
    lauXmlDom.removeChild(lauXmlNode);
    


    Agh stupid me, it was a property #-o

    Thanks Kine :thumbsup:
    K.S.
  • Options
    KisuKisu Member Posts: 381
    One more thing...

    I didn't want to start new topic as this is quite close to the previous one.

    As navision leaves empty element tags on the xml file how those elements could be checked and then removed with xmldom?

    I'm sure there is a way to check the elements if their values are not set. This would be very usefull with huge invoices, would save alot file size and bandwidth on transfering the file.
    K.S.
  • Options
    ara3nara3n Member Posts: 9,256
    You would have to do it through xmldom. Basically write a generic function that loops through all the children and call it recursively.
    You would in the function checked the value of each node and if it's blank, remove the child.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    gbierkensgbierkens Member Posts: 49
    I have a simular problem (trying to delete the <xml>-tag) but I'm not familuar with using the the XML automation objects. Can someone help me where to put the above sollution in my code.
    (using NAV 2009 SP1 classic)
    //XML Export
    XMLfile.CREATE('F:\Outbound\PO.xml');
    XMLfile.CREATEOUTSTREAM(OutStreamObj);
    
    XMLPORT.EXPORT(50007,OutStreamObj,gRecPurchaseHeader);
    XMLfile.CLOSE;
    

    I tried to do the following:
    After "XMLfile.CREATEOUTSTREAM(OutStreamObj);" add the code:
    XMLfile.CREATE('F:\Outbound\PO.xml');
    XMLfile.CREATEOUTSTREAM(OutStreamObj);
    
    CREATE(lauXmlDom);
    
    lauXmlDom.load(OutStreamObj);
    lauXmlNode := lauXmlDom.firstChild;
    lauXmlDom.removeChild(lauXmlNode);
    
    XMLPORT.EXPORT(50007,OutStreamObj,gRecPurchaseHeader);
    XMLfile.CLOSE;
    

    What would be the right way to do this?
  • Options
    KisuKisu Member Posts: 381
    gbierkens wrote:
    I have a simular problem (trying to delete the <xml>-tag) but I'm not familuar with using the the XML automation objects. Can someone help me where to put the above sollution in my code.
    (using NAV 2009 SP1 classic)
    //XML Export
    XMLfile.CREATE('F:\Outbound\PO.xml');
    XMLfile.CREATEOUTSTREAM(OutStreamObj);
    
    XMLPORT.EXPORT(50007,OutStreamObj,gRecPurchaseHeader);
    XMLfile.CLOSE;
    

    I tried to do the following:
    After "XMLfile.CREATEOUTSTREAM(OutStreamObj);" add the code:
    XMLfile.CREATE('F:\Outbound\PO.xml');
    XMLfile.CREATEOUTSTREAM(OutStreamObj);
    
    CREATE(lauXmlDom);
    
    lauXmlDom.load(OutStreamObj);
    lauXmlNode := lauXmlDom.firstChild;
    lauXmlDom.removeChild(lauXmlNode);
    
    XMLPORT.EXPORT(50007,OutStreamObj,gRecPurchaseHeader);
    XMLfile.CLOSE;
    

    What would be the right way to do this?


    I'm not 100% sure but the second code seems okay to me or if the remove child does not work then the problem might be in the process queue.

    First the load thingy needs the file or stream of string (xml data) where the remove child selects the first element, first child. then remove child nukes the first tag which is probably the <xml> and last the file exports out.

    I hope you get it working. It took me a week to get this done first time :)
    K.S.
  • Options
    gbierkensgbierkens Member Posts: 49
    Something still seems to go wrong. I get the following error:

    http://img543.imageshack.us/i/foutmeldingf.png/

    Any ideas?
  • Options
    Joe_MathisJoe_Mathis Member Posts: 173
    I would try it a little differently than what you have...
    VAR
       gRecPurchaseHeader : Record 38
       XMLDOMDocument : Automation :'Microsoft XML, v6.0'.DOMDocument;
       XMLNode : Automation :'Microsoft XML, v6.0'.IXMLDOMNode;
       TempBlob : Record 99008535;
       OutStreamObj : OutStream;
       InStreamObj : InStream;
    
    IF ISCLEAR(XMLDOMDocument) THEN BEGIN
      CREATE(XMLDOMDocument);
      XMLDOMDocument.async := FALSE;
    END;
    
    TempBlob.Blob.CREATEOUTSTREAM(OutStreamObj);
    
    XMLPORT.EXPORT(50007,OutStreamObj,gRecPurchaseHeader);
    
    TempBlob.Blob.CREATEINSTREAM(InStreamObj);
    
    XMLDOMDocument.load(InStreamObj);
    XMLNode := XMLDOMDocument.firstChild;
    XMLDOMDocument.removeChild(XMLNode);
    XMLDOMDocument.save('F:\Outbound\PO.xml');
    
    
    This works, I would probably add some more logic in that would give an error/message if there was nothing to do and maybe parameterize the file name for the save though. :D
Sign In or Register to comment.