Hi,
I have a set of XMLPorts created, each to a specific XML file with different tags.
All the XML files are placed in a folder with a generic name, so i have no idea on which XMLPort to use.
So, my idea is to loop through the folder, and one by one, open the XML file, identify a specific tag that will tell me which XMLPort I should use.
So I create the following structure (this is just an example):
File.open(filename)
File.createinstream(instream);
Create(XMLDoc)
XMLDoc.Load(instream)
OperationID(XMLDoc)
The function OperationID as the following code:
OperationID(VAR XMLDocIn : Automation "'Microsoft XML, v3.0'.DOMDocument")
XMLNodeCurr := XMLDocIn.documentElement;
IF FindNode(XMLNodeCurr,'DocumentType',XMLReturnedNode) THEN
IF STRLEN(XMLReturnedNode.text) > 0 THEN
Operation := XMLReturnedNode.text;
In theory this should work and the tag "DocumentType" should be found and I would now exactly which XMLPort to use.
Problem is that the FindNode function doesn't seem to be able to find the tag in question (yes, it is there in the XML file) and I suspect that the XMLDoc is either empty or doesn't contain the full XML file.
Any ideas or suggestions? Thanks.
Update: The XMLDoc is not empty. It just retrieves the first tag of the XML file and it's not the one I am interested in.
The XML structure is like this:
<CustomXML> <- this is the tag being retrieved right now
<MessageHeader>
<InterfaceID>123</InterfaceID>
<DocumentType>STOCK</DocumentType> <- this is the tag I need to retrieve
</MessageHeader>
<MessageBody>
<ContentList>
<DocumentID>1</DocumentID>
.
.
.
.
.
.
and so on
0
Answers
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
I tried it your way (and I hope it works. But for now i get this error message:
Microsoft Business Solutions-Navision
The length of the text string exceeds the size of the string buffer.
OK
This is the code, similar to what you posted:
IF ISCLEAR(XMLDoc) THEN
CREATE(XMLDoc);
XMLDoc.load("Import Folder"+FileName);
XMLNode := XMLDoc.selectSingleNode('//CustomXML/MessageHeader/InterfaceID/SenderID/ReceiverID/DocumentType/');
IF NOT ISCLEAR(XMLNode) THEN
MESSAGE(XMLNode.text);
I get this error in :
XMLNode := XMLDoc.selectSingleNode('//CustomXML/MessageHeader/InterfaceID/SenderID/ReceiverID/DocumentType/');
XMLNode is defined as:
Name DataType Subtype Length
XMLNode Automation 'Microsoft XML, v3.0'.IXMLDOMNode
And this is the XML structure
<CustomXML>
..<MessageHeader>
....<InterfaceID>123</InterfaceID>
....<SenderID>123</SenderID>
....<ReceiverID>123</ReceiverID>
....<DocumentType>STOCK</DocumentType>
..</MessageHeader>
jpjesus@netcabo.pt
I missread the xml file you have.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Now I understand the structure to use.
Right now I get no runtime error but the result is not the expected tag value. Instead I get this:
version="1.0" encoding="ISO-8859-2"
which is part if the very first line of the XML message:
<?xml version="1.0" encoding="ISO-8859-2" ?>
Any ideas why?
jpjesus@netcabo.pt
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Thank you very much for the help.
I do have one last question... where did you get this information? Is there a NAV manual, help file, from where I can get more information?
PS: Never underestimate the power of the backslash....
jpjesus@netcabo.pt
It is actually the MS XML DOM library .
You can read about it here. http://msdn.microsoft.com/en-us/library/aa153035.aspx
There are many examples on the web as well.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n