In Navision there are 2 ways to handle XMLs. In all versions it is possible to use the automation Microsoft XML and from Navision 4 it is possible to use XML ports.
XML ports are thought not my preferred object, because they are limited. They work in the same way as a dataport. Therefore in the following we will concentrate us on the use of the automation Microsoft XML.
Before we are able to load/read an XML document, we must define a variable, which will provide us with a container for the document.
Define the variable XMLDom as Microsoft XML – DomDocument
Because we are using automations, we have to create the instant at first:
CREATE(XMLDom);
Now we are ready to load a XML document into the container. There are 2 ways:
1. Loading from a text variable
XMLText := '<"1.0" encoding="ISO-8859-1"?>';
XMLText += 'SystemStatus';
XMLDom.loadXML(XMLText);
2. Loading from a file
XMLFile := 'c:\text.xml';
XMLDom.load(XMLFile);
By the way, the XML file could also be at text stream.
As soon the XML Document has been loaded, we are ready to add tags and read tags.
There are 2 ways to read XMLs. You can parse the XML Document as Nodes or as Elements. Nodes are though often Elements with sub elements. Elements do not contain sub elements.
Tags a common referee to Nodes and Elements
1. Reading as Nodes:
XMLNodeList := XMLDoc.getElementsByTagName(Tag);
Node := XMLNodeList.item(0);
IF NOT ISCLEAR(Node) THEN
ReturnValue := Node.text;
Where XMLNodeList is Microsoft XML IXMLDOMNodeList and Node is Microsoft XML IXMLDOMNode
2. Reading as Elements:
Element := XMLDoc.selectSingleNode(TagName);
IF NOT ISCLEAR(Element) THEN BEGIN
ReturnValue := Element.text;
Where Element is Microsoft XML IXMLDOMElement
If you instead of reading wants to build a XML Document you can also do this in 2 ways.
1. Create a XML from a text variable:
Building the XML
XMLText := '<"1.0" encoding="ISO-8859-1"?>';
XMLText += '
XMLDom.loadXML(XMLText);
Saving the XML:
XMLDom.save(xmlfile);
XML:
<"1.0" encoding="ISO-8859-1"?>
2. Creating an Init XML and then adding elements /nodes:
Build initial XML:
InitXML := '<"1.0" encoding="ISO-8859-1"?>'+
'
XMLDom.load(InitXML);
Add Element:
Root := XMLdoc.documentElement;
NewTag := XMLDom.createElement('Type');
NewTag.text := 'SystemStatus';
Root.appendChild(NewTag);
XML:
<"1.0" encoding="ISO-8859-1"?>
Hi, i am working on interchange of invoices between two companies using xml ports..i have done export of the sales invoice into xml file and now i need to import it..and i am not sure how to do it..
i would like to ask you for helping hand
i am using navision 4.0 SP3
thanks
Hi!
I guess, that if you are using XML ports to export the data – you are doing it in a ways similar to this:
outFile.CREATE('c:outxml.xml');
outFile.CREATEOUTSTREAM(SH_outStream);
XMLPORT.EXPORT(50000, SH_outStream);
outFile.Close;
Where you are using the XMLPORT to handle the xml format.
If you know wants to import the data again, then you can either use the XMLPORT again or handle it yourself by using XMLDom. The use of XMLDom has been described above. When using XMLPort you must do it in a way similar to this:
inFile.OPEN('c:inxml.xml');
inFile.CREATEINSTREAM(SH_inStream);
XMLPORT.IMPORT(50000, SH_inStream);
inFile.CLOSE;