Selecting a particular node in XML document

shettarvikas
Member Posts: 106
Hi,
Please let me know, how to navigate in XML doc to find a particular node and its value,
XML file sample,
Here I am not able to user selectSingleNode function because it is giving me the 1st XML value (i.e. AED/INR). I wan to navigate to a particular node say for US dollar, its 46th item, how can I navigate to that item and select the value of description in the child node
Nav Code is,
Please suggest.
Thnaks in advance,
Regards,
Vikas
Please let me know, how to navigate in XML doc to find a particular node and its value,
XML file sample,
item>
<title>AED/INR</title>
<link>http://xxx.com/INR/AED.aspx</link>
<guid>f770299c-1d99-4c84-981e-3eb95d7bf4fd</guid>
<pubDate>Thu, 27 May 2010 21:26:45 GMT</pubDate>
<description>1 Indian Rupee = 0.07883 United Arab Emirates Dirham</description>
<category>Middle East</category>
</item>
<item>
<title>ARS/INR</title>
<link>http://xxx.com/INR/ARS.aspx</link>
<guid>05d0b0aa-c5c2-49a1-828f-820a03734f70</guid>
<pubDate>Thu, 27 May 2010 21:26:45 GMT</pubDate>
<description>1 Indian Rupee = 0.08379 Argentine Peso</description>
<category>South America</category>
</item>
.... so on
Here I am not able to user selectSingleNode function because it is giving me the 1st XML value (i.e. AED/INR). I wan to navigate to a particular node say for US dollar, its 46th item, how can I navigate to that item and select the value of description in the child node
Nav Code is,
IF ISCLEAR(xmlHTTP) THEN CREATE(xmlHTTP); IF ISCLEAR(XMLDoc) THEN CREATE(XMLDoc); xmlHTTP.open('GET','http://themoneyconverter.com/INR/rss.xml',FALSE); xmlHTTP.send; XMLDoc := xmlHTTP.responseXML; XMLNode :=XMLDoc.selectSingleNode('//rss/channel/item/description'); IF NOT ISCLEAR(XMLNode) THEN MESSAGE(XMLNode.text); XMLDoc.save('C:\NavRSS2.xml'); CLEAR(XMLNode); CLEAR(XMLDoc); CLEAR(xmlHTTP);
Please suggest.
Thnaks in advance,
Regards,
Vikas
0
Comments
-
There are different ways.
First you can use a NodeList and go through its child-elements:
using WHILEXMLNodeList := XMLDoc.selectNodes('//rss/channel/item'); XMLNode := XMLNodeList.nextNode; WHILE NOT ISCLEAR(XMLNode) DO BEGIN MESSAGE(XMLNode.selectSingleNode('description').text); XMLNode := XMLNodeList.nextNode; END;
... or if you prefer FORXMLNodeList := XMLDoc.selectNodes('//rss/channel/item'); FOR i := 0 TO XMLNodeList.length DO BEGIN XMLNode := XMLNodeList.item(i); MESSAGE(XMLNode.selectSingleNode('description').text); END;
Or the "direct" way:XMLNode := XMLDoc.selectSingleNode('//rss/channel/item[title="USD"]/description');
Best regards
Falk0 -
Hi FAFL,
what can I do to prove if one node exists or not?
For example: the node description by USD doesn't exists.
XMLNode := XMLDoc.selectSingleNode('//rss/channel/item[title="USD"]/description');0 -
Hi Navsyst2,
After your xpath-query, you check if the node is null (ISCLEAR(XmlNode)) to find it out .0
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