XMLPort - Remove heading on XMLport output?
David_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.
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
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
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com
0
Answers
-
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.com0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions