XMLPort - Remove heading on XMLport output?

David_CoxDavid_Cox Member Posts: 509
Hi Guys,
I have not had much call to use XML, so my knowledge here is very light, most of the files I work with are Excel or CSV.

I have to export Sales Invoices, and "Navision 5.01" add a header line to the file, this causes it not to open in a browser, we want to remove the first line of the XML.
<?xml version="1.0" encoding="UTF-16" standalone="no" ?>

I have searched and found a couple of solutions from April 2011, none of which I could get to work, I used the last one in this post from Joe Mathis.
Remove heading on XMLport output?

I get the error, "Could not Invoke the member removeChild", then a message unknown error code returned, with no detail :(

Does anyone have a working example of this?

Regards

David
Analyst Developer with over 17 years Navision, Contract Status - Busy
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com

Answers

  • David_CoxDavid_Cox Member Posts: 509
    Just thought I would share a solution, it might save someone some pain, as I searched a lot for a fix and settled for this simple solution, to remove the first line!

    The xml file I have been exporting has to have an attribute "ns0:" and an external schema!

    In the xml port I added a row:
    TagName    TagType    SourceType  DataSource
    xmlns:ns0   Attribute   Text	    xmlns1
    

    OnPreXMLport()
    xmlns1 := 'http://TheWebsite.Sales.Inv.Schema.'; 
    

    On export this gave me a lines like:
    <?xml version="1.0" encoding="UTF-16" standalone="no" ?>
    <ns0:Document xmlns:ns0="http://TheWebsite.Sales.Inv.Schema."> 
    	<ns0:DHeader>
    

    I have to then remove the first line for it to import and open up in Internet Explorer, you would think it was easy but! ](*,)
    I found this post on Dynamics User and adapted the code to remove just the first line.

    Variables:
    XMLOutStream = OutStream		
    ProcessFileName =	Text 200 (2 Dimensions)
    FromFile = File		
    ToFile	= File		
    TextLine	= Text 250
    BinaryChunk = Binary 2000
    PositionInFile = Integer		
    PostionInBinary = Integer		
    
    This is what the code does.
      Export the xml file open it in text mode find the file position at the end of the first line Close the file Open it in binary mode Create and read the file into a new file Truncate the new file close the files Delete the tempory file
    ProcessFileName[1] := 'temp.xml';
    ProcessFileName[2] := PassedSalesInv."No." + '.xml';
    
    IF FILE.EXISTS(ProcessFileName[1])THEN
      FILE.ERASE(ProcessFileName[1]);
    
    FromFile.CREATE(ProcessFileName[1]);
    FromFile.CREATEOUTSTREAM(XMLOutStream);
    XMLPORT.EXPORT(50002,XMLOutStream,PassedSalesInv);
    FromFile.CLOSE;
    
    FromFile.OPEN(ProcessFileName[1]);
    FromFile.TEXTMODE := TRUE;
    FromFile.READ(TextLine);
    PositionInFile := FromFile.POS;
    FromFile.CLOSE;
    
    //Reopen Source file for binary read
    FromFile.OPEN(ProcessFileName[1]);
    FromFile.TEXTMODE := FALSE;
    FromFile.SEEK(PositionInFile);
    
    //Create destination file to copy content
    IF EXISTS(ProcessFileName[2]) THEN
      ERASE(ProcessFileName[2]);
    
    ToFile.CREATE(ProcessFileName[2]);
    ToFile.OPEN(ProcessFileName[2]);
    ToFile.TEXTMODE := FALSE;
    
    //Read rest of file in Binary chunks, write to destination file
    WHILE FromFile.POS < FromFile.LEN DO BEGIN
      CLEAR(BinaryChunk);  
      FromFile.READ(BinaryChunk);
      ToFile.WRITE(BinaryChunk);
    END;
    
    PostionInBinary := FromFile.LEN - PositionInFile;
    ToFile.SEEK(PostionInBinary);
    ToFile.TRUNC;
    
    FromFile.CLOSE;
    ToFile.CLOSE;
    
    IF EXISTS(ProcessFileName[1]) THEN
      ERASE(ProcessFileName[1]);
    

    Hpe this helps someone else \:D/
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
Sign In or Register to comment.