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

logu_cbelogu_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

Comments

  • ara3nara3n Member Posts: 9,256
    can you paste your xml file?

    your issue is this line

    XMLDom.selectSingleNode('itemcode');

    selectSingleNode can't find the node.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3nara3n Member Posts: 9,256
    To save the file. Do this.

    XMLDom.load(InMsg.GetStream());
    XMLDom.save('C:\xmlfile.xml');
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • logu_cbelogu_cbe Member Posts: 54
    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,
    Logu
  • XypherXypher Member Posts: 297
    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.)
  • ara3nara3n Member Posts: 9,256
    Change your code to this.


    XMLNodeItemCode := XMLDom.selectSingleNode('inventory/item/itemcode');
    XMLNodeAval := XMLDom.selectSingleNode('inventory/item/availability');
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • logu_cbelogu_cbe Member Posts: 54
    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,
    Logu
  • XypherXypher Member Posts: 297
    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)
  • ara3nara3n Member Posts: 9,256
    I suggest to also get the Microsoft XML, v6.0 and install that.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.