Transform XML with XSL: Root element is missing

JGoudriaanJGoudriaan 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:

olnoetx9m95i.png


I created the code below:

7ou1phjgunxo.png

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:

4ul8qq8tuxk5.png


The lvNetMemoryStreamSource is not empty.

Can someone please tell and explain me what's wrong with my code?

Best Answer

  • JGoudriaanJGoudriaan Member Posts: 3
    Answer ✓
    Problem solved. After 'pXMLDocument.Save(lvNetMemoryStreamSource) were two lines missing:
    lvNetMemoryStreamSource.Flush();
    lvNetMemoryStreamSource.Position := 0;

    Credits to Renger for giving me the solution!

Answers

  • DuikmeesterDuikmeester Member Posts: 308
    edited 2019-05-02
    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?
  • JGoudriaanJGoudriaan Member Posts: 3
    Duikmeester,
    Thanks for your reply!

    Do you mean I should not close the XMLWriter? If I don't, the following error arises:

    9ky9mua2bf6z.png


    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.
  • krikikriki Member, Moderator Posts: 9,115
    [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!


  • JGoudriaanJGoudriaan Member Posts: 3
    Answer ✓
    Problem solved. After 'pXMLDocument.Save(lvNetMemoryStreamSource) were two lines missing:
    lvNetMemoryStreamSource.Flush();
    lvNetMemoryStreamSource.Position := 0;

    Credits to Renger for giving me the solution!
Sign In or Register to comment.