Error in parsing xml with navision

subhastersubhaster Member Posts: 64
Hi !
I am getting an error, when I am trying to read an XML file . The function body for reading an xml looks like this :-

XmlNodeList := XmlDom.getElementsByTagName('first');
XmlNode := XmlNodeList.item(0);
VMsg:=XmlNode.selectNodes('msg').item(0).text;
MESSAGE(VMsg);

where XMLNodeList is an automation datatype with the subtype as 'Microsoft XML, v4.0'.IXMLDOMNodeList
XML Node is also automation datatype with subtype as 'Microsoft XML, v4.0'.IXMLDOMNode

The error is like this :-
This message is for the C/AL programmers :-
You must instantiate/assign the automation variable.

If someone can throw some light on this , it would be of extreme help for me.
Subhasish Chakraborty,
Systems Analyst,
MBS Dynamics.

Comments

  • ara3nara3n Member Posts: 9,257
    On top of your code you have to enter
    If isclear(xmldom) then
    Create(xmldom);
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • subhastersubhaster Member Posts: 64
    Yup, i wrote that at the top of the code. but still it is giving me the error.
    Subhasish Chakraborty,
    Systems Analyst,
    MBS Dynamics.
  • ara3nara3n Member Posts: 9,257
    Turn on the debugger and see where it stops.

    My guess it stops
    XmlNode := XmlNodeList.item(0);

    which means XmlDom.getElementsByTagName('first'); returns a null.

    Make sure 'first' is a xml tag.

    in the xml file
    <first> something</first>


    If you put your xml file structure it would help.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • subhastersubhaster Member Posts: 64
    Yes Rashid, you are right ....
    i ,by mistake, was passing an xml file like this :-
    <first><msg>this is test</msg></first>
    in to the message queue. But unfortunately, it was apparently an XML file , but actually , it was getting sent in to the MSMQ as a text file.
    As a result , <first> was not a tag !

    Thanks !
    Subhasish Chakraborty,
    Systems Analyst,
    MBS Dynamics.
  • ara3nara3n Member Posts: 9,257
    I am glad that your was resolved.
    Ahmed Rashed Amini
    Independent Consultant/Developer


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