Retrieve a specific Node from XML

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gpearson
Posts: 84
Joined: Wed Feb 03, 2010 12:55 pm

Retrieve a specific Node from XML

Post by gpearson » Thu Feb 25, 2010 8:56 pm

I am finally getting to the point of understanding how to post information and retrieve it from a web service and it has been a very productive day today. If my xml packet looks like

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
		<location type="CITY">
		<termsofservice link="http://www.wunderground.com/members/tos.asp#api" />
		<country>US</country>
  <state>IN</state>
  <city>Goshen</city>
  <tz_short>EST</tz_short>
  <tz_unix>America/Indianapolis</tz_unix>
  <lat>41.59891891</lat>
  <lon>-85.78933716</lon>
  <zip>46528</zip>
  <magic>1</magic>
  <wmo>99999</wmo>
		<requesturl>/US/IN/Goshen.html</requesturl>
		<wuiurl>http://www.wunderground.com/US/IN/Goshen.html</wuiurl>
		<radar>
		<image_url><![CDATA[http://resize.wunderground.com/cgi-bin/resize_convert?ox=gif&url=radblast/cgi-bin/radar/WUNIDS_composite%3Fcenterlat=41.59891891%26centerlon=-85.78933716%26radius=15%26newmaps=1%26smooth=1]]></image_url>
		<url><![CDATA[http://www.wunderground.com/radar/radblast.asp?ID=IWX&region=a4&lat=41.59891891&lon=-85.78933716]]></url>
		</radar>
		<webcams>
		<cam>
  <handle>bkthedj</handle>
  <camid>bkthedjCAM2</camid>
  <camindex>2</camindex>
  <type>ftp</type>
  <assoc_station_id></assoc_station_id>
  <link>http://www.buddyking.net</link>
  <linktext>1/2 mi from Notre Dame - West View</linktext>
  <cameratype>Toshiba IK-WB11 PTZ</cameratype>
  <organization></organization>
  <neighborhood>1/2 mi. from Notre Dame - looking West</neighborhood>
  <address>1824 Ridgewood Cir</address>
  <zip>46617</zip>
  <city>South Bend</city>
  <state>IN</state>
  <country>US</country>
  <tzname>America/Indianapolis</tzname>
  <hexant>4</hexant>
  <hexid>17374</hexid>
  <lat>41.69031525</lat>
  <lon>-86.22117615</lon>
  <updated>2010-02-25 12:57:42</updated>
  <downloaded>0000-00-00 00:00:00</downloaded>
  <hash></hash>
  <isrecent>1</isrecent>
  <frequency>300</frequency>
  <CURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/b/k/bkthedj/2/current.jpg?t=1267122158</CURRENTIMAGEURL>
  <WIDGETCURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/b/k/bkthedj/2/widget.jpg?t=1267122158</WIDGETCURRENTIMAGEURL>
  <CAMURL>http://www.wunderground.com/webcams/bkthedj/2/show.html</CAMURL>
  </cam>
		<cam>
  <handle>pawcam</handle>
  <camid>pawcamCAM1</camid>
  <camindex>1</camindex>
  <type>ftp</type>
  <assoc_station_id></assoc_station_id>
  <link>http://aarh.biz</link>
  <linktext>Aarh Hosting & Design (aarh.biz)</linktext>
  <cameratype>Intel PC Camera CS431</cameratype>
  <organization></organization>
  <neighborhood></neighborhood>
  <address>88th Ave</address>
  <zip>49067</zip>
  <city>Marcellus</city>
  <state>MI</state>
  <country>US</country>
  <tzname>America/New_York</tzname>
  <hexant>1</hexant>
  <hexid>17374</hexid>
  <lat>42.09835052</lat>
  <lon>-85.77735901</lon>
  <updated>2010-02-24 21:05:37</updated>
  <downloaded>0000-00-00 00:00:00</downloaded>
  <hash></hash>
  <isrecent>1</isrecent>
  <frequency>300</frequency>
  <CURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/p/a/pawcam/1/current.jpg?t=1267122158</CURRENTIMAGEURL>
  <WIDGETCURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/p/a/pawcam/1/widget.jpg?t=1267122158</WIDGETCURRENTIMAGEURL>
  <CAMURL>http://www.wunderground.com/webcams/pawcam/1/show.html</CAMURL>
  </cam>
		<cam>
  <handle>fsgond</handle>
  <camid>fsgondCAM1</camid>
  <camindex>1</camindex>
  <type>ftp|0</type>
  <assoc_station_id></assoc_station_id>
  <link>http://www.parrcomputers.com</link>
  <linktext></linktext>
  <cameratype>D-link DCS-920</cameratype>
  <organization>PARR Computers</organization>
  <neighborhood></neighborhood>
  <address>28800 Madison Rd</address>
  <zip>46554</zip>
  <city>North Liberty</city>
  <state>IN</state>
  <country>US</country>
  <tzname>America/New_York</tzname>
  <hexant>4</hexant>
  <hexid>17374</hexid>
  <lat>41.57815552</lat>
  <lon>-86.42562103</lon>
  <updated>2010-02-25 13:21:37</updated>
  <downloaded>0000-00-00 00:00:00</downloaded>
  <hash></hash>
  <isrecent>1</isrecent>
  <frequency>300</frequency>
  <CURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/f/s/fsgond/1/current.jpg?t=1267122158</CURRENTIMAGEURL>
  <WIDGETCURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/f/s/fsgond/1/widget.jpg?t=1267122158</WIDGETCURRENTIMAGEURL>
  <CAMURL>http://www.wunderground.com/webcams/fsgond/1/show.html</CAMURL>
  </cam>
		<cam>
  <handle>kevinspagedotcom</handle>
  <camid>kevinspagedotcomCAM2</camid>
  <camindex>2</camindex>
  <type>ftp|0</type>
  <assoc_station_id>KMIBENTO1</assoc_station_id>
  <link>http://www.kevinspage.com</link>
  <linktext>kevinspage.com</linktext>
  <cameratype>WIFI P/T Cam</cameratype>
  <organization></organization>
  <neighborhood>Kevin and Patricia's</neighborhood>
  <address>295 Millburg Dr</address>
  <zip>49022</zip>
  <city>Benton Harbor</city>
  <state>MI</state>
  <country>US</country>
  <tzname>America/New_York</tzname>
  <hexant>5</hexant>
  <hexid>17374</hexid>
  <lat>42.11738968</lat>
  <lon>-86.33662415</lon>
  <updated>2010-02-25 13:08:40</updated>
  <downloaded>0000-00-00 00:00:00</downloaded>
  <hash></hash>
  <isrecent>1</isrecent>
  <frequency>300</frequency>
  <CURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/k/e/kevinspagedotcom/2/current.jpg?t=1267122158</CURRENTIMAGEURL>
  <WIDGETCURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/k/e/kevinspagedotcom/2/widget.jpg?t=1267122158</WIDGETCURRENTIMAGEURL>
  <CAMURL>http://www.wunderground.com/webcams/kevinspagedotcom/2/show.html</CAMURL>
  </cam>
		<cam>
  <handle>kevinspagedotcom</handle>
  <camid>kevinspagedotcomCAM1</camid>
  <camindex>1</camindex>
  <type>ftp|0</type>
  <assoc_station_id>KMIBENTO1</assoc_station_id>
  <link>http://www.kevinspage.com/</link>
  <linktext>Kevin and Patty's Place</linktext>
  <cameratype>Trendnet TV-IP410</cameratype>
  <organization></organization>
  <neighborhood></neighborhood>
  <address>295 Millburg Dr</address>
  <zip>49022</zip>
  <city>Benton Harbor</city>
  <state>MI</state>
  <country>US</country>
  <tzname>America/New_York</tzname>
  <hexant>5</hexant>
  <hexid>17374</hexid>
  <lat>42.11681366</lat>
  <lon>-86.33645630</lon>
  <updated>2010-02-25 13:22:18</updated>
  <downloaded>0000-00-00 00:00:00</downloaded>
  <hash></hash>
  <isrecent>1</isrecent>
  <frequency>300</frequency>
  <CURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/k/e/kevinspagedotcom/1/current.jpg?t=1267122158</CURRENTIMAGEURL>
  <WIDGETCURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/k/e/kevinspagedotcom/1/widget.jpg?t=1267122158</WIDGETCURRENTIMAGEURL>
  <CAMURL>http://www.wunderground.com/webcams/kevinspagedotcom/1/show.html</CAMURL>
  </cam>
		<cam>
  <handle>bambam3931</handle>
  <camid>bambam3931CAM2</camid>
  <camindex>2</camindex>
  <type>ftp</type>
  <assoc_station_id>KMIBRONS2</assoc_station_id>
  <link>http://bronsonweather.org</link>
  <linktext>Bronson Weather Live!</linktext>
  <cameratype>Panasonic BL C131</cameratype>
  <organization></organization>
  <neighborhood>Bethel Twnshp</neighborhood>
  <address>323 Cranson Rd</address>
  <zip>49028</zip>
  <city>Bronson</city>
  <state>MI</state>
  <country>US</country>
  <tzname>America/New_York</tzname>
  <hexant>4</hexant>
  <hexid>17375</hexid>
  <lat>41.82531738</lat>
  <lon>-85.09460449</lon>
  <updated>2010-02-25 11:53:34</updated>
  <downloaded>0000-00-00 00:00:00</downloaded>
  <hash></hash>
  <isrecent>1</isrecent>
  <frequency>300</frequency>
  <CURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/b/a/bambam3931/2/current.jpg?t=1267122158</CURRENTIMAGEURL>
  <WIDGETCURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/b/a/bambam3931/2/widget.jpg?t=1267122158</WIDGETCURRENTIMAGEURL>
  <CAMURL>http://www.wunderground.com/webcams/bambam3931/2/show.html</CAMURL>
  </cam>
		<cam>
  <handle>swimmerr</handle>
  <camid>swimmerrCAM1</camid>
  <camindex>1</camindex>
  <type>ftp</type>
  <assoc_station_id>KMIBATTL5</assoc_station_id>
  <link>http://</link>
  <linktext></linktext>
  <cameratype>Logitech 4000 Pro </cameratype>
  <organization>tedwhitman.com</organization>
  <neighborhood>Lakeview Area Battle Creek Michigan</neighborhood>
  <address>123 Foster Ave</address>
  <zip>49015</zip>
  <city>Battle Creek</city>
  <state>MI</state>
  <country>US</country>
  <tzname>America/New_York</tzname>
  <hexant>5</hexant>
  <hexid>17375</hexid>
  <lat>42.30276489</lat>
  <lon>-85.20333862</lon>
  <updated>2010-02-25 13:21:07</updated>
  <downloaded>0000-00-00 00:00:00</downloaded>
  <hash></hash>
  <isrecent>1</isrecent>
  <frequency>300</frequency>
  <CURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/s/w/swimmerr/1/current.jpg?t=1267122158</CURRENTIMAGEURL>
  <WIDGETCURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/s/w/swimmerr/1/widget.jpg?t=1267122158</WIDGETCURRENTIMAGEURL>
  <CAMURL>http://www.wunderground.com/webcams/swimmerr/1/show.html</CAMURL>
  </cam>
		<cam>
  <handle>Zooman</handle>
  <camid>ZoomanCAM1</camid>
  <camindex>1</camindex>
  <type>url|1</type>
  <assoc_station_id>KINFREMO3</assoc_station_id>
  <imageurl>http://www.snowlakecottagers.org/www/cam_1.jpg</imageurl>
  <link>http://www.snowlakecottagers.org</link>
  <linktext>Snow Lake</linktext>
  <cameratype>Creative Live! Wireless</cameratype>
  <organization>Snow Lake</organization>
  <neighborhood></neighborhood>
  <address>240 Ln 800 Snow Lake</address>
  <zip>46737</zip>
  <city>Fremont</city>
  <state>IN</state>
  <country>US</country>
  <tzname>America/Indianapolis</tzname>
  <hexant>3</hexant>
  <hexid>17375</hexid>
  <lat>41.73698425</lat>
  <lon>-85.02935791</lon>
  <updated>2010-02-25 13:20:45</updated>
  <downloaded>2010-02-25 13:20:45</downloaded>
  <hash>3a701deb854e2f8ec26b5b62c55da3db50376ae2</hash>
  <isrecent>1</isrecent>
  <frequency>300</frequency>
  <CURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/z/o/Zooman/1/current.jpg?t=1267122158</CURRENTIMAGEURL>
  <WIDGETCURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/z/o/Zooman/1/widget.jpg?t=1267122158</WIDGETCURRENTIMAGEURL>
  <CAMURL>http://www.wunderground.com/webcams/Zooman/1/show.html</CAMURL>
  </cam>
		<cam>
  <handle>cwnorrell</handle>
  <camid>cwnorrellCAM1</camid>
  <camindex>1</camindex>
  <type>ftp</type>
  <assoc_station_id>KINWARSA1</assoc_station_id>
  <link>http://www.timeswrsw.com/craig/cam/</link>
  <linktext>Lake Cam</linktext>
  <cameratype>Logitech</cameratype>
  <organization>Times-Union</organization>
  <neighborhood>Winona Lake</neighborhood>
  <address>1025 Country Club Ln</address>
  <zip>46580</zip>
  <city>Warsaw</city>
  <state>IN</state>
  <country>US</country>
  <tzname>America/New_York</tzname>
  <hexant>5</hexant>
  <hexid>17734</hexid>
  <lat>41.22636032</lat>
  <lon>-85.83985138</lon>
  <updated>2010-02-25 12:58:20</updated>
  <downloaded>0000-00-00 00:00:00</downloaded>
  <hash></hash>
  <isrecent>1</isrecent>
  <frequency>300</frequency>
  <CURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/c/w/cwnorrell/1/current.jpg?t=1267122158</CURRENTIMAGEURL>
  <WIDGETCURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/c/w/cwnorrell/1/widget.jpg?t=1267122158</WIDGETCURRENTIMAGEURL>
  <CAMURL>http://www.wunderground.com/webcams/cwnorrell/1/show.html</CAMURL>
  </cam>
		<cam>
  <handle>OwlsHouse</handle>
  <camid>OwlsHouseCAM1</camid>
  <camindex>1</camindex>
  <type>ftp</type>
  <assoc_station_id>KINHUNTI6</assoc_station_id>
  <link>http://www.w6dsp.org/index.html</link>
  <linktext></linktext>
  <cameratype>Canon Op30</cameratype>
  <organization></organization>
  <neighborhood></neighborhood>
  <address>6830 N Goshen Rd</address>
  <zip>46750</zip>
  <city>Huntington</city>
  <state>IN</state>
  <country>US</country>
  <tzname>America/Indianapolis</tzname>
  <hexant>4</hexant>
  <hexid>17734</hexid>
  <lat>40.92821884</lat>
  <lon>-85.54673767</lon>
  <updated>2010-02-25 13:22:05</updated>
  <downloaded>0000-00-00 00:00:00</downloaded>
  <hash></hash>
  <isrecent>1</isrecent>
  <frequency>300</frequency>
  <CURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/o/w/OwlsHouse/1/current.jpg?t=1267122158</CURRENTIMAGEURL>
  <WIDGETCURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/o/w/OwlsHouse/1/widget.jpg?t=1267122158</WIDGETCURRENTIMAGEURL>
  <CAMURL>http://www.wunderground.com/webcams/OwlsHouse/1/show.html</CAMURL>
  </cam>
		<cam>
  <handle>AB9HG</handle>
  <camid>AB9HGCAM1</camid>
  <camindex>1</camindex>
  <type>ftp|0</type>
  <assoc_station_id></assoc_station_id>
  <link>http://</link>
  <linktext></linktext>
  <cameratype>Logitech Orbit AF</cameratype>
  <organization></organization>
  <neighborhood></neighborhood>
  <address>1700 Park Ave</address>
  <zip>46590</zip>
  <city>Winona Lake</city>
  <state>IN</state>
  <country>US</country>
  <tzname>America/Indianapolis</tzname>
  <hexant>5</hexant>
  <hexid>17734</hexid>
  <lat>41.22024536</lat>
  <lon>-85.82163239</lon>
  <updated>2010-02-25 13:18:21</updated>
  <downloaded>0000-00-00 00:00:00</downloaded>
  <hash></hash>
  <isrecent>1</isrecent>
  <frequency>300</frequency>
  <CURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/a/b/AB9HG/1/current.jpg?t=1267122158</CURRENTIMAGEURL>
  <WIDGETCURRENTIMAGEURL>http://icons.wunderground.com/webcamramdisk/a/b/AB9HG/1/widget.jpg?t=1267122158</WIDGETCURRENTIMAGEURL>
  <CAMURL>http://www.wunderground.com/webcams/AB9HG/1/show.html</CAMURL>
  </cam>
  </webcams>
		<nearby_weather_stations>
<airport>
  <station>
  <city>Goshen</city>
  <state>IN</state>
  <country>US</country>
  <icao>KGSH</icao>
  <lat>41.52999878</lat>
  <lon>-85.79000092</lon>
  </station>
  <station>
  <city>Elkhart</city>
  <state>IN</state>
  <country>US</country>
  <icao>KEKM</icao>
  <lat>41.72000122</lat>
  <lon>-86.00000000</lon>
  </station>
  <station>
  <city>Warsaw</city>
  <state>IN</state>
  <country>US</country>
  <icao>KASW</icao>
  <lat>41.27000046</lat>
  <lon>-85.83000183</lon>
  </station>
  <station>
  <city>Sturgis</city>
  <state>MI</state>
  <country>US</country>
  <icao>KIRS</icao>
  <lat>41.81000137</lat>
  <lon>-85.44000244</lon>
  </station>
</airport>
<pws>
  <station>
  <neighborhood><![CDATA[APRSWXNET Nappanee                   IN US]]></neighborhood>
  <city><![CDATA[Nappanee]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[MD0836]]></id>
  <distance_km><![CDATA[19]]></distance_km>
  <distance_mi><![CDATA[11]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[APRSWXNET Jamestown                  IN US]]></neighborhood>
  <city><![CDATA[Osceola]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[MC1697]]></id>
  <distance_km><![CDATA[21]]></distance_km>
  <distance_mi><![CDATA[12]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[]]></neighborhood>
  <city><![CDATA[Edwardsburg]]></city>
  <state><![CDATA[MI]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[KMIEDWAR2]]></id>
  <distance_km><![CDATA[21]]></distance_km>
  <distance_mi><![CDATA[12]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[INDOT MP-96 Elkhart East Plaza]]></neighborhood>
  <city><![CDATA[Elkhart]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[MIN025]]></id>
  <distance_km><![CDATA[22]]></distance_km>
  <distance_mi><![CDATA[13]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[Elkhart North Point]]></neighborhood>
  <city><![CDATA[Elkhart]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[KINELKHA2]]></id>
  <distance_km><![CDATA[24]]></distance_km>
  <distance_mi><![CDATA[14]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[Elkhart County West]]></neighborhood>
  <city><![CDATA[Elkhart]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[KINELKHA4]]></id>
  <distance_km><![CDATA[24]]></distance_km>
  <distance_mi><![CDATA[14]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[MesoWest Constantine                      MI US MAWN]]></neighborhood>
  <city><![CDATA[White Pigeon]]></city>
  <state><![CDATA[MI]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[MMICNT]]></id>
  <distance_km><![CDATA[26]]></distance_km>
  <distance_mi><![CDATA[16]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[Reverewood]]></neighborhood>
  <city><![CDATA[Mishawaka]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[KINMISHA2]]></id>
  <distance_km><![CDATA[28]]></distance_km>
  <distance_mi><![CDATA[17]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[HADS NORTH BRANCH ELKHART RIVER AT CO IN US]]></neighborhood>
  <city><![CDATA[Wawaka]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[MCPEI3]]></id>
  <distance_km><![CDATA[28]]></distance_km>
  <distance_mi><![CDATA[17]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[Twin Branch Industrial Park]]></neighborhood>
  <city><![CDATA[Mishawaka]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[KINMISHA5]]></id>
  <distance_km><![CDATA[29]]></distance_km>
  <distance_mi><![CDATA[17]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[School Science Room]]></neighborhood>
  <city><![CDATA[Constantine]]></city>
  <state><![CDATA[MI]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[KMICONST2]]></id>
  <distance_km><![CDATA[29]]></distance_km>
  <distance_mi><![CDATA[17]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[APRSWXNET Leesburg                   IN US]]></neighborhood>
  <city><![CDATA[North Webster]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[MD1684]]></id>
  <distance_km><![CDATA[32]]></distance_km>
  <distance_mi><![CDATA[19]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[Granger Cherry Trails]]></neighborhood>
  <city><![CDATA[Granger]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[KINGRANG2]]></id>
  <distance_km><![CDATA[32]]></distance_km>
  <distance_mi><![CDATA[19]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[INDOT MP 121- Howe - Lagrange]]></neighborhood>
  <city><![CDATA[Howe]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[MIN023]]></id>
  <distance_km><![CDATA[33]]></distance_km>
  <distance_mi><![CDATA[20]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[Near West Side]]></neighborhood>
  <city><![CDATA[Bremen]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[KINBREME1]]></id>
  <distance_km><![CDATA[35]]></distance_km>
  <distance_mi><![CDATA[21]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[Milton Township]]></neighborhood>
  <city><![CDATA[Niles]]></city>
  <state><![CDATA[MI]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[KMINILES3]]></id>
  <distance_km><![CDATA[36]]></distance_km>
  <distance_mi><![CDATA[22]]></distance_mi>
  </station>
  <station>
  <neighborhood><![CDATA[APRSWXNET South Bend                 IN US]]></neighborhood>
  <city><![CDATA[South Bend]]></city>
  <state><![CDATA[IN]]></state>
  <country><![CDATA[US]]></country>
  <id><![CDATA[MC7428]]></id>
  <distance_km><![CDATA[39]]></distance_km>
  <distance_mi><![CDATA[23]]></distance_mi>
  </station>
</pws>
</nearby_weather_stations>
		</location>
In my script I find the number of children for the nearby airports which in this case will return 4. I then get a random number from 1 to the max of the number of children. If my script returns 3 how can I go about getting the ICAO from the 3rd airport from this group of airport stations which is KASW

Any Ideas on how to do this
---
Graham Pearson
Goshen, IN USA

We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com

massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

Re: Retrieve a specific Node from XML

Post by massung » Mon Mar 01, 2010 9:23 pm

Take a look at revXMLChildNames. You can use that and then index (untested code, but I've used it before successfully, you may need to tweak what's below some):

Code: Select all

put revXMLRootNode(tTree) into tRoot
put revXMLChildNames(tTree, tRoot, "airport",true) into tAirport

revXMLNodeContents(tTree, tRoot & "/" & tAirport[1] & "/name") into tAirport_1
revXMLNodeContents(tTree, tRoot & "/" & tAirport[2] & "/name") into tAirport_2
revXMLNodeContents(tTree, tRoot & "/" & tAirport[3] & "/name") into tAirport_3

...
So, given the above, you should be able to easily use a random number to index into tAirport and grab all the data you need from it.

HTH,

Jeff M.

gpearson
Posts: 84
Joined: Wed Feb 03, 2010 12:55 pm

Re: Retrieve a specific Node from XML

Post by gpearson » Tue Mar 02, 2010 5:22 pm

For my knowledge as I investigate this, does the Array start at 0 like it does within the flash environment?

Example would be Airport[0] would be the first item in the array
Airport[1] would be the second item in the array
etc.
---
Graham Pearson
Goshen, IN USA

We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com

massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

Re: Retrieve a specific Node from XML

Post by massung » Tue Mar 02, 2010 6:31 pm

Honestly, I don't remember, but I'd put money down on them starting at 1, given that everything else in Rev starts at 1. It wouldn't be too difficult to set a breakpoint and look inside the array and see. ;)

Jeff M.

gwbasic
Posts: 34
Joined: Tue Mar 16, 2010 6:39 am

Re: Retrieve a specific Node from XML

Post by gwbasic » Sat Mar 20, 2010 1:01 am

I have this xml data that my boss wants uploaded/store to a mysql database:

Code: Select all

	<?xml version="1.0" encoding="UTF-8" standalone="no"?>
	<table> 
		<record>
			<id>100</id>
			<last_name>smith</last_name>
			<first_name>john</last_name>
			<country>usa</country>
		</record>
		<record>
			<id>200</id>
			<last_name>gates</last_name>
			<first_name>william</last_name>
			<country>usa</country>	
		</record>
		<record>
			<id>300</id>
			<last_name>mcdonald</last_name>
			<first_name>ronald</last_name>
			<country>japan</country>	
		</record>
		<record>
			<id>400</id>
			<last_name>chips</last_name>
			<first_name>fish</last_name>
			<country>uk</country>	
		</record>	
	</table>
I can't get the examples to work on this. I'm newbie to rev and not an xml expert either. I would appreciate any assistance on this or an example code would be nice.
Last edited by gwbasic on Mon Mar 22, 2010 1:31 am, edited 1 time in total.

worcestersource
Posts: 24
Joined: Wed Mar 17, 2010 3:51 pm
Contact:

Re: Retrieve a specific Node from XML

Post by worcestersource » Sat Mar 20, 2010 9:54 am

You've got a few mismatched close tags there, so the XML library won't be able to form a tree for you.

Specifically, in each record, you've closed the <first_name> tag with a </last_name> tag.

<record>
<id>100</id>
<last_name>smith</last_name>
<first_name>john</last_name>
<country>usa</country>
</record>

Cheers,


Steve

gwbasic
Posts: 34
Joined: Tue Mar 16, 2010 6:39 am

Re: Retrieve a specific Node from XML

Post by gwbasic » Mon Mar 22, 2010 1:29 am

Code: Select all

	<?xml version="1.0" encoding="UTF-8" standalone="no"?>
	<table> 
		<record>
			<id>100</id>
			<last_name>smith</last_name>
			<first_name>john</first_name>
			<country>usa</country>
		</record>
		<record>
			<id>200</id>
			<last_name>gates</last_name>
			<first_name>william</first_name>
			<country>usa</country>	
		</record>
		<record>
			<id>300</id>
			<last_name>mcdonald</last_name>
			<first_name>ronald</first_name>
			<country>japan</country>	
		</record>
		<record>
			<id>400</id>
			<last_name>chips</last_name>
			<first_name>fish</first_name>
			<country>uk</country>	
		</record>	
	</table>
Corrected the typo. Below is the php code that I wanted to convert to Rev:
<?php
$doc = new DOMDocument();
$doc->load( 'people.xml' );

$records = $doc->getElementsByTagName( record" );
foreach( $records as $record )
{
$last_names = $record->getElementsByTagName( "last_name" );
$last_name = $last_names->item(0)->nodeValue;

$first_names = $record->getElementsByTagName( "first_name" );
$first_name = $first_names->item(0)->nodeValue;

$countries = $record->getElementsByTagName( "country" );
$country = $countries->item(0)->nodeValue;

echo "$last_name - $first_name - $country\n";
}
?>

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Retrieve a specific Node from XML

Post by mwieder » Mon Mar 22, 2010 7:41 am

I'd be inclined to do something like:

Code: Select all

function readxml pFilePath
    local tXMLTreeID
    local tRoot
    local tResponse
    local tChildNode
    local tID
    local aRecords
    
    put revCreateXMLTreeFromFile(pFilePath, false, true, false) into tXMLTreeID
    put revXMLRootNode(tXMLTreeID) into tRoot -- "table"
    put revXMLFirstChild(tXMLTreeID,tRoot) into tResponse -- "record"
    repeat while "xmlerr" is not in tResponse
        put revXMLNodeContents(tXMLTreeID, tResponse & "/id") into tID
        put revXMLNodeContents(tXMLTreeID, tResponse & "/last_name") into aRecords[tID]["lastname"]
        put revXMLNodeContents(tXMLTreeID, tResponse & "/first_name") into aRecords[tID]["firstname"]
        put revXMLNodeContents(tXMLTreeID, tResponse & "/country") into aRecords[tID]["country"]
        put revXMLNextSibling(tXMLTreeID,tResponse) into tResponse
        if tResponse is empty then
            exit repeat
        end if
    end repeat
    return aRecords
end readxml
if you pass this function a path to a file (as returned from an "answer file" command, for instance) it will return you an array (aRecords) with all your records neatly arranged by id. The php code looks a bit cleaner, but you're not doing any error checking and you're creating three separate arrays.

gwbasic
Posts: 34
Joined: Tue Mar 16, 2010 6:39 am

Re: Retrieve a specific Node from XML

Post by gwbasic » Tue Mar 23, 2010 12:12 am

Thanks!

RobertC
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 46
Joined: Sun Feb 04, 2007 3:43 pm

Re: Retrieve a specific Node from XML

Post by RobertC » Tue Nov 08, 2011 3:12 pm

Hello,

I have a somewhat similar question, so I post it here.
How do I get hold of the comments in an XML document?
revCreateXMLTree parses a document and gives you an ID to handle the resulting tree.
But I find no revXMLxxx() to get any comment text, but using revXMLText with the ID of the tree created by revCreateXMLTree, I do get the text back including the comments.

Have I overlooked something?

Robert
The Old Rant Robert.

Post Reply