Options

Simple XML export with .NET?

thomastthomast Member Posts: 102
edited 2015-08-28 in NAV Three Tier
Hi Guys,

Could anyone tell me how to make a codeunit which can export a couple of fields from the customer table in XML but using the .NET xml variable called system.xml?

I am trying to understand how the basics of this works and would expect this could be done in a couple of lines of code....

Thank you!!! :-)

Thomas.

Comments

  • Options
    JonasAJonasA Member Posts: 28
    edited 2015-08-28
    I recommend that you look at 6224 XML DOM Management.

    Just start with calling the constructor and from there it's just using the XMLDOMMgt.AddElement method.
    XMLResultDoc:= XMLResultDoc.XmlDocument;
    XMLResultDoc.LoadXml('<?xml version="1.0" encoding="utf-8" ?><root/>');
    
    XMLRootNode := XMLResultDoc.DocumentElement;
    XMLDOMMgt.AddElement(XMLRootNode, 'description', '', XMLRootNode.NamespaceURI, XMLCreatedNode);
    
    Types:
    Name	DataType	Subtype	Length
    XMLDOMMgt	Codeunit	XML DOM Management	
    XMLResultDoc	DotNet	System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    XMLCreatedNode	DotNet	System.Xml.XmlNode.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    XMLRootNode	DotNet	System.Xml.XmlNode.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    


    The code above will produce:
    <?xml version="1.0" encoding="utf-8" ?>
    <root>
      <description/>
    </root>
    

    From there you have the XMLCreatedNode which you can add to to create a child to your description element.
    Remember that if you want to save, you should use XMLResultDoc.Save('Filename')

    Edit: forgot the types.
  • Options
    Andreea_AmariteiAndreea_Amaritei Member Posts: 3
    But XMLRootNode, what type should be? Could you make a reference to other tutorials regarding .NET in C/AL?
  • Options
    JonasAJonasA Member Posts: 28
    Hi Andreea.

    I just edited my post to contain the XMLRootNode type.

    I don't have a reference for .NET in C/AL. I just try and see what works.
Sign In or Register to comment.