Multiple XML-file import

Christian_WandborgChristian_Wandborg Member Posts: 23
Hi,

Using the 'XML Import Sample v1.0i' as is from the Download section, I have no problems. I would like the sample to import multiple xml-files simultaneously though, but faced with the error message (attached image), I'm stuck.

Now, as mentioned, the sample are working just fine as is with minor adjustments to accommodate the file structure.

If the existing code on the OnRun trigger is inactivated and/or replaced with:

XMLFile.INIT;
XMLFile.RESET;
XMLFile.SETRANGE(Path, 'C:\TEMP\TEST\ARCHIVE\');
XMLFile.SETRANGE("Is a file", TRUE);
IF XMLFile.FINDFIRST THEN BEGIN
REPEAT
FileName := XMLFile.Name;
OpenXMLDocument(FileName,XMLDocument);
ImportXMLFile(FileName);
UNTIL XMLFile.NEXT = 0;
END ELSE BEGIN
MESSAGE('No files to import');
END;

The errormessage is triggered.

These are the Locals on OnRun:
Name DataType Subtype
XMLDocument Automation 'Microsoft XML, version 2.0'.DOMDocument
XMLFile Record File

My xml-structure is as follows:

<ORDER>
<HEADING>
<DEPT>200</DEPT>
<NO>5000</NO>
</HEADING>
</ORDER>

If you have any suggestions, please don't hesitate :)
Regards
Christian

Answers

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    What code do you have in function OpenXMLDocument?
    Have you created the XMLDOM like

    CREATE(XmlDoc);
  • ta5ta5 Member Posts: 1,164
    edited 2012-03-12
    Hi

    Use the create statement to initialize the automation variable xmlDocument.
    Hope this helps
    Thomas
  • Christian_WandborgChristian_Wandborg Member Posts: 23
    Hi,
    This is the code (Emiel Romein) http://www.mibuso.com/dlinfo.asp?FileID=329


    Documentation()
    
    OnRun()
    {
    "XML File Name" := 'C:\TEMP\TEST\ARCHIVE\TEST_1.xml'; // File name parameter.
    ImportXMLFile("XML File Name"); // Import XML File
    }
    
    XMLFile.INIT;
    XMLFile.RESET;
    XMLFile.SETRANGE(Path, 'C:\TEMP\TEST\ARCHIVE\');
    XMLFile.SETRANGE("Is a file", TRUE);
    IF XMLFile.FINDFIRST THEN BEGIN
      REPEAT
        FileName := XMLFile.Name;
        OpenXMLDocument(FileName,XMLDocument);
        ImportXMLFile(FileName);
      UNTIL XMLFile.NEXT = 0;
    END ELSE BEGIN
      MESSAGE('No files to import');
    END;
    
    ImportXMLFile(FileName : Text[1024])
    OpenXMLDocument(FileName,XMLDocument); // Initialize and Load XML Document.
    
    LoadNodeList(XMLDocument,XMLNodeList,'ORDER/HEADING');
    
    LoadNode(XMLNodeList,XMLNode,0); // Load Node Number 1 (0 = 1) from Node List.
    
    MessageValues(XMLNode.selectNodes('DEPT').item(0).text);
    MessageValues(XMLNode.selectNodes('NO').item(0).text);
    
    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);
    
    Regards
    Christian
  • Christian_WandborgChristian_Wandborg Member Posts: 23
    Thanks fpr input guys, this one did the trick:
      REPEAT
        FileName := FileLocInbox + XMLFile.Name;
        ImportXMLFile(FileName);
        MoveXMLFile;
      UNTIL XMLFile.NEXT = 0;
    
    Regards
    Christian
Sign In or Register to comment.