Error in XMLDomNode while reading data in node..!!

logu_cbe
Member Posts: 54
Hi Guys,
Following is code i copied from MSDN Talking to Navision and modified for my specific usage.
I am facing problem in reading the Specific node. I am getting an error in "XMLNodeItemCode.text" while i am trying to read one specific node.
Error: Message to CAL Prog. The Automation Variable has not been initiated.
Can any of you guys help me?
CC2::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")
//Get the Message
InMsg := InMessage;
//Load the message into an XML document and find a node
IF NOT ISCLEAR(XMLDom) THEN
CLEAR(XMLDom);
CREATE(XMLDom);
XMLDom.load(InMsg.GetStream());
XMLNodeItemCode := XMLDom.selectSingleNode('itemcode');
XMLNodeAval := XMLDom.selectSingleNode('available');
//Calculate Stock
Item.RESET;
IF Item.GET(FORMAT(XMLNodeItemCode.text)) THEN begin
Item.CALCFIELDS(Item.Inventory);
XMLNodeAval.text := FORMAT(Item.Inventory);
END ELSE BEGIN
XMLNodeAval.text := FORMAT(0);
END;
//Open the response queue and create a new message
MQBus.OpenWriteQueue('.\private$\fromnavision',0,0);
OutMsg := CC2.CreateoutMessage('Message [url=queue://]queue://[/url].\private$\fromnavision');
OutS := OutMsg.GetStream();
//Fill the message and send it
OutS.WRITE(XMLDom.xml);
OutMsg.Send(0);
Thanks in Advance,
Logu
Following is code i copied from MSDN Talking to Navision and modified for my specific usage.
I am facing problem in reading the Specific node. I am getting an error in "XMLNodeItemCode.text" while i am trying to read one specific node.
Error: Message to CAL Prog. The Automation Variable has not been initiated.
Can any of you guys help me?
CC2::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")
//Get the Message
InMsg := InMessage;
//Load the message into an XML document and find a node
IF NOT ISCLEAR(XMLDom) THEN
CLEAR(XMLDom);
CREATE(XMLDom);
XMLDom.load(InMsg.GetStream());
XMLNodeItemCode := XMLDom.selectSingleNode('itemcode');
XMLNodeAval := XMLDom.selectSingleNode('available');
//Calculate Stock
Item.RESET;
IF Item.GET(FORMAT(XMLNodeItemCode.text)) THEN begin
Item.CALCFIELDS(Item.Inventory);
XMLNodeAval.text := FORMAT(Item.Inventory);
END ELSE BEGIN
XMLNodeAval.text := FORMAT(0);
END;
//Open the response queue and create a new message
MQBus.OpenWriteQueue('.\private$\fromnavision',0,0);
OutMsg := CC2.CreateoutMessage('Message [url=queue://]queue://[/url].\private$\fromnavision');
OutS := OutMsg.GetStream();
//Fill the message and send it
OutS.WRITE(XMLDom.xml);
OutMsg.Send(0);
Thanks in Advance,
Logu
0
Comments
-
can you paste your xml file?
your issue is this line
XMLDom.selectSingleNode('itemcode');
selectSingleNode can't find the node.0 -
To save the file. Do this.
XMLDom.load(InMsg.GetStream());
XMLDom.save('C:\xmlfile.xml');0 -
Thank you for your reply.
my xml file sample is
<?xml version="1.0" encoding="utf-8" ?>
- <inventory>
- <item>
<id>0</id>
<itemcode>logu</itemcode>
<availability>0</availability>
</item>
</inventory>
Please note i am not going to save it as a XML file.
We need to get as a MSMQ Xml string. After updating the availablity we need to return as a MSMQ Xml string.
Can you please help me reading the Item Code? (XML Node)
Thank you,
Logu0 -
Please list the declarations you have setup for your XMLDom variables.
Reason I ask is... you shouldn't have to "initiate" an automation that 'stems' from an initiated automation. (No matter if the node is found or not. Result of your XMLDomNodeVar.Text would equal '' not an error.)0 -
Change your code to this.
XMLNodeItemCode := XMLDom.selectSingleNode('inventory/item/itemcode');
XMLNodeAval := XMLDom.selectSingleNode('inventory/item/availability');0 -
Thank you for your reply for you guys...
Still it is showing error while it is in the line....
MESSAGE(XMLNodeItemCode.text);
Error is: This message for C/AL Programmers:
This automation variable has not been initiated.
You can initiate it by either creating or assigning it.
//CODE BIT
XMLDom.load(InMsg.GetStream());
XMLNodeItemCode := XMLDom.selectSingleNode('inventory/item/itemcode');
XMLNodeAval := XMLDom.selectSingleNode('inventory/item/availability');
MESSAGE(XMLNodeItemCode.text);
//CODE BIT
Variable Declaration as follows
XMLDom Automation 'Microsoft XML, v3.0'.DOMDocument
XMLNodeItemCode Automation 'Microsoft XML, v3.0'.IXMLDOMNode
XMLNodeAval Automation 'Microsoft XML, v3.0'.IXMLDOMNode
Can you guys help me in solving this?
Thank you,
Logu0 -
Well first off I know ara3n asked if you could load & save. But did you actually attempt at doing the following?
XMLDom.load(InMsg.GetStream()); XMLDom.save('C:\test.xml');
If you can do that fine then only other guess I have without actually testing with code of my own, try this...XMLDom.load(InMsg.GetStream()); XMLRoot := XMLDom.documentElement; XMLNodeItemCode := XMLRoot.selectSingleNode('inventory/item/itemcode'); XMLNodeAval := .....
(XMLRoot = IXMLDOMElement)0 -
I suggest to also get the Microsoft XML, v6.0 and install that.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 320 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