Read XML DOM Document into table

zeon
Member Posts: 130
Hi,
I'm trying to download some currency exchange rates in an xml file, and then read them into a table, but I can't seem to get it right. Have tried to foloow the advises in other threads without luck.
The format of the xml file is the following:
My Code looks like this. For now I'm saving the values in MyText just to see the value, but later it must be saved to Currency Exchange Rates.
Function FindNode from CU13601
How can I get the values of the attributes in <Cube currency="USD" rate="1.2863" />
I'm trying to download some currency exchange rates in an xml file, and then read them into a table, but I can't seem to get it right. Have tried to foloow the advises in other threads without luck.
The format of the xml file is the following:
<?xml version="1.0" encoding="UTF-8" ?> - <Envelope> <subject>Reference rates</subject> - <Sender> <name>European Central Bank</name> </Sender> - <Cube> - <Cube time="2012-05-14"> <Cube currency="USD" rate="1.2863" /> <Cube currency="JPY" rate="102.64" /> <Cube currency="BGN" rate="1.9558" /> </Cube> </Cube> </Envelope>
My Code looks like this. For now I'm saving the values in MyText just to see the value, but later it must be saved to Currency Exchange Rates.
IF ISCLEAR(XMLHTTP) THEN IF NOT CREATE(XMLHTTP) THEN ERROR(Text000); GLSetup.GET; GLSetup.TESTFIELD("URL Latest Currency Rates"); // URL := 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml'; // URL := 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'; URL := GLSetup."URL Latest Currency Rates"; XMLHTTP.open('GET',URL,FALSE); XMLHTTP.send(); IF (XMLHTTP.status = 200) THEN BEGIN IF ISCLEAR(XMLDoc) THEN IF NOT CREATE(XMLDoc) THEN ERROR(Text000); XMLDoc.async := FALSE; XMLDoc.load(XMLHTTP.responseBody); IF RemoveNamespace(XMLDoc,XMLDoc,Filename) THEN BEGIN WITH TmpCurrExchRate DO BEGIN XMLNode := XMLDoc.documentElement; XMLNodeList := XMLNode.selectNodes('Envelope'); XMLNodeList.reset; REPEAT TmpCurrExchRate.INIT; XMLNode := XMLNodeList.nextNode; IF FindNode(XMLNode,'Sender',XMLReturnedNode) THEN IF STRLEN(XMLReturnedNode.text) > 0 THEN MyText := XMLReturnedNode.text IF FindNode(XMLNode,'Cube',XMLReturnedNode) THEN IF STRLEN(XMLReturnedNode.text) > 0 THEN MyText := XMLReturnedNode.text; IF FindNode(XMLNode,'Cube currency',XMLReturnedNode) THEN IF STRLEN(XMLReturnedNode.text) > 0 THEN MyText := XMLReturnedNode.text; IF TmpCurrExchRate.INSERT(TRUE) THEN; UNTIL COUNT = (XMLNodeList.length); END;
Function FindNode from CU13601
IF ISCLEAR(XMLRootNode) THEN EXIT(FALSE); IF NOT NormalCaseMode THEN NodePath := NodePath; FoundXMLNode := XMLRootNode.selectSingleNode(NodePath); IF ISCLEAR(FoundXMLNode) THEN EXIT(FALSE) ELSE EXIT(TRUE);
XMLNode Automation 'Microsoft XML, v6.0'.IXMLDOMNode XMLReturnedNode Automation 'Microsoft XML, v6.0'.IXMLDOMNode XMLNodeList Automation 'Microsoft XML, v6.0'.IXMLDOMNodeList
How can I get the values of the attributes in <Cube currency="USD" rate="1.2863" />
0
Answers
-
Hi Peter,
It didn't help, BUT instead you brought me unto something else, and in my search I found this msdn blog entry http://blogs.msdn.com/b/nav_developer/archive/2008/03/31/sample-of-how-to-read-a-simple-xml-document-using-msxml-dom-in-nav.aspx
that can help me process the XML DOM Document. I'm not finished yet, but now I can get to the values of the attributes, and from there put it into a table :-) Damn, that has taken me a loooooong time ](*,)
So, thanks anyway!
zeon0 -
Hmm, surprised my suggestion doesn't work. I have this code running at several sites:
GetAttribute(VAR XMLNode : Automation "'Microsoft XML, v6.0'.IXMLDOMNode";AttributeName : Text[250];VAR AttributeValue : Text[250]) : Boolean XMLAttribute := XMLNode.selectSingleNode(STRSUBSTNO('@%1',AttributeName)); IF ISCLEAR(XMLAttribute) THEN EXIT(FALSE); AttributeValue := XMLAttribute.text; EXIT(TRUE);
I guess the difference is the XMLAttribute, which isn't a IXMLDOMNode but a IXMLDOMAttribute.Regards
Peter0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions