Instream to XMLDoc
jpjesus
Member Posts: 45
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
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
Joao Jesus
jpjesus@netcabo.pt
jpjesus@netcabo.pt
0
Answers
-
This code in your Function should return the value.
XmlNode := XMLDocIn..selectSingleNode('//CustomXML/MessageHeader/InterfaceID/DocumentType/'); IF NOT ISCLEAR(XmlNode) THEN BEGIN MESSAGE(XmlNode.text); End;0 -
Hi Rashed
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>Joao Jesus
jpjesus@netcabo.pt0 -
change the line to the following
XMLNode := XMLDoc.selectSingleNode('//CustomXML/MessageHeader/DocumentType/');
I missread the xml file you have.0 -
Thanks,
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?Joao Jesus
jpjesus@netcabo.pt0 -
Found the issue. You need to remove the last backslash.
XMLNode := XMLDoc.selectSingleNode('//CustomXML/MessageHeader/DocumentType');0 -
That's it. Works great now! =D>
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....
Joao Jesus
jpjesus@netcabo.pt0 -
The information has nothing to do with NAV,
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 328 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
