Error during Import of XML-Files

RallnusRallnus Member Posts: 79
edited 2004-12-01 in Navision Attain
I try to import a XML-file like it is done in the example of romein.

The "LoadnodeList"-function is successful.

During "selectNodes" appears an error:

"This message ist for C/AL programmers:

This automation variable hast not been instantiated
You can instantiate it by either creating or assigning it."

Does somebody know what i shall do?
Is some literature about these problems availible?
Rallnus (Yamaha FJ1200 - '89 / 25th anniversary was great!)

Answers

  • pduckpduck Member Posts: 147
    post your code please ... you missed a Create() somewhere.
  • RallnusRallnus Member Posts: 79
    The code is the same as in the download of emiel romein.

    http://www.mibuso.com/dlinfo.asp?FileID=329

    I've nly changed some variables.

    When I define a new Data Type "Automation" for a parameter, this error will appear. It seems that there ist a way to define variables within a parameter of type Automation.

    The modified code of emiel romein:

    "XML File Name" := 'c:\Orderbeispiel4.xml'; // File name parameter.
    ImportXMLItemList("XML File Name"); // Import XML File

    ImportXMLItemList(FileName : Text[1024])
    OpenXMLDocument(FileName,XMLDocument); // Initialize and Load XML Document.

    LoadNodeList(XMLDocument,XMLNodeList,'item/ORDER_HEADER');
    // Define Dialog
    TotNumbOfRecs := XMLNodeList.length; // Number of "records" in XML file. TotNumbOfRecs var needed for progress dialog.
    Window.OPEN(Text000);
    // end define dialog

    MESSAGE('%1',TotNumbOfRecs);

    LoadNode(XMLNodeList,XMLNode,0); // Load Node Number 1 (0 = 1) from Node List.

    REPEAT // Loop through all Nodes.



    MessageValues(XMLNode.selectNodes('ORDER_ID').item(0).text); // <

    XMLNode := XMLNodeList.nextNode; // Next Node Element
    UNTIL ISCLEAR(XMLNode);


    OpenXMLDocument(FileName : Text[1024];VAR XMLDocument : Automation "'Microsoft XML, version 2.0'.DOMDocument")
    // Initialize and Load XML Document.
    // General Function.

    IF ISCLEAR(XMLDocument) THEN // Initialize
    CREATE(XMLDocument);

    XMLDocument.load(FileName); // Load XML File

    MessageValues(FieldValue : Text[1024])
    MESSAGE(FieldValue); // Just displaying the values on screen.

    LoadNodeList(XMLDocument : Automation "'Microsoft XML, version 2.0'.DOMDocument";VAR XMLNodeList : Automation "'Microsoft XML, version
    // Load Node List from XML Document.
    // General Function.

    XMLNodeList := XMLDocument.getElementsByTagName(ElementName);

    LoadNode(XMLNodeList : Automation "'Microsoft XML, version 2.0'.IXMLDOMNodeList";VAR XMLNode : Automation "'Microsoft XML, version 2.0'
    // Load Node from Node List.
    // General Function.

    XMLNode := XMLNodeList.item(RecordIndex);

    Xml-File:

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <item>
    <ORDER_HEADER>
    <ORDER_INFO>
    <ORDER_ID>4500932746</ORDER_ID>
    </ORDER_INFO>
    </ORDER_HEADER>
    </item>
    Rallnus (Yamaha FJ1200 - '89 / 25th anniversary was great!)
  • pduckpduck Member Posts: 147
    your xql statement in selectNodes cannot catch the ORDER_ID node because the current position of XMLNode is 2 levels above <ORDER_ID>.

    in your list you have all child-nodes from <ORDER_HEADER> so only <ORDER_INFO> is in the list. now you try to find <ORDER_ID> which is a child of <ORDER_INFO> and not of <ORDER_HEADER>.

    try:
    MessageValues(XMLNode.selectNodes('ORDER_INFO/ORDER_ID').item(0).text);

    hope you understand it :)
  • RallnusRallnus Member Posts: 79
    Thanks a lot. When you once understand the priciple, then it's no problem.

    :D
    Rallnus (Yamaha FJ1200 - '89 / 25th anniversary was great!)
Sign In or Register to comment.