|
| [WD22] XML file processing |
| Iniciado por guest, 28,ene. 2018 05:29 - 2 respuestas |
| |
| | | |
|
| |
| Publicado el 28,enero 2018 - 05:29 |
Hello,
I need to read and process data from a xml file. The content of the xml file (a.xml) is
Contents of a.xml ============= <?xml version="1.0" encoding="UTF-16LE" standalone="no"?>
BaseAccountsYBaseAccounts1NBaseAccounts2Y
I tried with the following code, but all fails. =================================================== IF fFileExist("a.xml") THEN XMLSource = fLoadText("a.xml", foAnsi) XMLRes = XMLDocument("XMLDoc", XMLSource) // Was the document created? IF XMLRes = False THEN Error("The following problem was detected: " + ErrorInfo()) ELSE info("The document was successfully created. It is ready to be used.") END
XMLRes = XMLFirst("XMLDoc") IF XMLRes = True THEN info("First XMLElementName", XMLElementName("XMLDoc")) info("First XMLParentName", XMLParentName("XMLDoc")) info("First XMLElementName", XMLElementName("XMLDoc")) info("First XMLData", XMLData("XMLDoc")) info("FIrst XMLChild", XMLChild("XMLDoc")) ELSE info("first failed", ErrorInfo(errMessage)) END
XMLRes = XMLRoot("XMLDoc") info("XML Res root ", XMLRes) IF XMLRes = True THEN info("Root XMLElementName", XMLElementName("XMLDoc")) info("Root XMLParentName", XMLParentName("XMLDoc")) info("Root XMLElementName", XMLElementName("XMLDoc")) info("Root XMLData", XMLData("XMLDoc")) info("Root XMLChild", XMLChild("XMLDoc")) ELSE info("root failed", ErrorInfo(errMessage)) END
XMLRes = XMLFind("XMLDoc", "DBProfile_row") info("XML Res find", XMLRes) IF XMLRes = True THEN info("Root XMLElementName", XMLElementName("XMLDoc")) info("Root XMLParentName", XMLParentName("XMLDoc")) info("Root XMLElementName", XMLElementName("XMLDoc")) info("Root XMLData", XMLData("XMLDoc")) info("Root XMLChild", XMLChild("XMLDoc")) ELSE info("find failed", ErrorInfo(errMessage)) END
========================================================
I get only failed message. Am I missing anything?
Happiness Always BKR Sivaprakash |
| |
| |
| | | |
|
| | |
| |
| Publicado el 28,enero 2018 - 10:33 |
I use the following to read notifications of payments received. The xml I receive is pretty simple, they can be quite complex, but it may give you an idea.
lsFileList = fListFile(StringBuild("%1*.xml",CompleteDir(gclApplication:msPayments)),frNotRecursive) IF lsFileList <> "" THEN ldExpiryDate..Day += 2 FOR EACH STRING XMLInput OF lsFileList SEPARATED BY CR lsXMLInfo = fLoadText(XMLInput) lbReadRes = XMLDocument("XMLPayment",lsXMLInfo) IF lbReadRes = True THEN XMLRoot("XMLPayment") XMLFind("XMLPayment","PaymentRef",XMLTag+XMLAttribute) IF XMLFound("XMLPayment") = True THEN XMLFirst("XMLPayment") lsPaymentRef = XMLData("XMLPayment") XMLNext("XMLPayment") lsCustID = XMLData("XMLPayment") XMLNext("XMLPayment") lsTransDate = XMLData("XMLPayment") ldTransDate = StringToDate(lsTransDate,"YYYYMMDD") XMLNext("XMLPayment") lsInvNum = XMLData("XMLPayment") XMLNext("XMLPayment") lsClaimRef = XMLData("XMLPayment") XMLNext("XMLPayment") lsSrcAmount = XMLData("XMLPayment") XMLNext("XMLPayment") lsSrcCurrency = XMLData("XMLPayment") //Locate and validate the invoice HExecuteQuery(qryInvoiceDetail,hQueryDefault,lsInvNum,lsClaimRef) .............................. As said quite simple, just reading the attribute values but similar applies for tags. All dependent on the format of what you are receiving. There are quite a few examples in the Help and of course you can step through the whole process in debug to find out which line of your code initially fails. |
| |
| |
| | | |
|
| | |
| |
| Publicado el 03,febrero 2018 - 09:04 |
Thanks DerekT.
Issue is with the XML file generated from other application.
By removing encoding in the line, I could read those values/ atrributes.
<?xml version="1.0" encoding="UTF-16LE" standalone="no"?>
Is there any way to read and process this file with this encoding set ?
Happiness Always BKR Sivaprakash |
| |
| |
| | | |
|
| | | | |
| | |
|