Checking for RootElement in XML-files

BlackBird
BlackBird Member Posts: 52
Hi There,

I'm designing an interface between 2 applications based on the exchange of XML-files.
The idea is that the XML-files are saved in a directoryand i have to process the files from this directory. The XML-files can store different data. F.i.: one stores Items and the other stores Customers.
When importing the XML-files i want to check the rootelements in the XMLf-files so that i can trigger the right XML-port.
Example:
XML-file #1 has root element <Items></Items>
XML-file #2 has root element <Customers></Customers>.
I have a codeunit that checks to specified directory for *.xml-files. When i process the directory it has to run XML-port 50.000 when it finds the XML-files with root <Items> and XML-port 50.001 when it finds the XML-file with root <Customer>.
Does anyone have a hint as how to do this?

Thnkx.

Hans

Comments

  • ClausJohnsen
    ClausJohnsen Member Posts: 3
    Hi BlackBird,

    You can use XMLDOM.
    xlDoc = Automation 'Microsoft XML, v3.0'.DOMDocument

    CASE xmlDoc.documentEmelent.nodeName OF
    'Items': bla bla bla.
    'Customers': Bla bla bla
    END;
  • rvduuren
    rvduuren Member Posts: 92
    Hello Hans,

    This worked for me, let me know if this is what you mean..
    Globals
    XmlDom Automation 'Microsoft XML, v5.0'.DOMDocument
    CurrNode Automation 'Microsoft XML, v5.0'.IXMLDOMNode
    
    IF ISCLEAR(tXmlDoc) THEN
      CREATE(XmlDoc);
    
    XmlDoc.load('c:\data.xml');
    
    CurrNode := XmlDoc.selectSingleNode('//item');
    IF NOT ISCLEAR(CurrNode) THEN BEGIN
      << start xmlport item>>
    END;
    
    CurrNode := XmlDoc.selectSingleNode('//customer');
    IF NOT ISCLEAR(CurrNode) THEN BEGIN
      << start xmlport customer>>
    END;
    
    Met vriendelijke groet, best regards,

    Rvduuren
  • BlackBird
    BlackBird Member Posts: 52
    Both Rik and Claus,

    Tnkx for the reply. Both methods work for me!

    Hans