Transform XML with XSL: Root element is missing

JGoudriaan
Member Posts: 3
Hi there,
I'm working with Dynamics NAV for more than two years now, but I'm quite new to using webservices and XML/XSL.
For a customer (using Dynamics NAV 2017) I have to create a function that creates a XML-file and apply a XSL-StyleSheet to it.
I searched the internet for a clue how to figure this out. I found several posts on forums, so I had some ideas.
The XML-file is like:

I created the code below:

The pXMLDocument-variable has been created in another function and contains the XML-file.
The code works until "lvNetXslCompiledTransform.Transform(lvNetXMLReaderSource, lvNetXMLWriter);"
Then it generates the following error:

The lvNetMemoryStreamSource is not empty.
Can someone please tell and explain me what's wrong with my code?
I'm working with Dynamics NAV for more than two years now, but I'm quite new to using webservices and XML/XSL.
For a customer (using Dynamics NAV 2017) I have to create a function that creates a XML-file and apply a XSL-StyleSheet to it.
I searched the internet for a clue how to figure this out. I found several posts on forums, so I had some ideas.
The XML-file is like:

I created the code below:

The pXMLDocument-variable has been created in another function and contains the XML-file.
The code works until "lvNetXslCompiledTransform.Transform(lvNetXMLReaderSource, lvNetXMLWriter);"
Then it generates the following error:

The lvNetMemoryStreamSource is not empty.
Can someone please tell and explain me what's wrong with my code?
0
Best Answer
-
Problem solved. After 'pXMLDocument.Save(lvNetMemoryStreamSource) were two lines missing:
lvNetMemoryStreamSource.Flush();
lvNetMemoryStreamSource.Position := 0;
Credits to Renger for giving me the solution!0
Answers
-
You close the XmlWriter before using it in the Transform:
lvNetXMLWriter.Close; ....Transform(...,lvNetXMLWriter);
P.S.: post text instead of screenshot so it can be copy+pasted for creating a test.
P.P.S.: does you XML transform correct with the given XSL using a tool like XML notepad or something?0 -
Duikmeester,
Thanks for your reply!
Do you mean I should not close the XMLWriter? If I don't, the following error arises:
Ad. P.S. Thanks for your advice; should I post the code in text now?
Ad. P.P.S I do not know that tool. I will search for it on the internet.0 -
[Topic moved from 'NAV Tips & Tricks' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Problem solved. After 'pXMLDocument.Save(lvNetMemoryStreamSource) were two lines missing:
lvNetMemoryStreamSource.Flush();
lvNetMemoryStreamSource.Position := 0;
Credits to Renger for giving me the solution!0
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