file line by line and determine the correct tag each time.
The easy way is to let the microsoft.xmldom COM object do the work. The
following example reads an XML file containing customer account number and
transaction details.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | static void XMLReadCustTrans(Args _args) { FileIoPermission permission; XMLDocument doc; XMLNode rootNode, AccNode, NameNode, transNode; XMLNodeList custTransList; XMLParseError xmlError; int i; ; permission= new FileIoPermission("C:\\CustTrans.xml",'r'); permission.assert(); // Get the XML document doc = new XMLDocument(); doc.load("C:\\CustTrans.xml"); xmlError = doc.parseError(); if (xmlError && xmlError.errorCode() != 0) throw error(strFmt("Error: %1",xmlError.reason())); rootNode = doc.documentElement(); // Get the customer account and name from the document AccNode = rootNode.selectSingleNode("//CustomerAccount"); NameNode = rootNode.selectSingleNode("//CustomerName"); setprefix(AccNode.text()+ ' ' + NameNode.text()); // Select all the customer transactions into a nodelist custTransList = rootNode.selectNodes("//TransactionDetail"); for (i = 0; i < custTransList.length(); i++) { transNode = custTransList.item(i); info(transNode.selectSingleNode("TransText").text() + ' ' + transNode.selectSingleNode("TransAmount").text()); } } |
Best Regards,
Hossein Karimi
No comments:
Post a Comment