Retrieving XML values from node of complex document with PHP
Posted: Sun Apr 18, 2010 3:20 pm
well, this is the first time i have posted something like this. My first post on devnetwork!
I have been fighting this for about 5 days and have gotten nowhere.
i have this url: http://waterservices.usgs.gov/WOF/Insta ... riod=PT51M
which returns this XML:
<timeSeriesResponse xsi:schemaLocation="http://www.cuahsi.org/waterML/1.0/ http://waterservices.usgs.gov/WOF/WaterML-1.0.xsd">
<queryInfo>
<creationTime>2001-01-01T22:22:22</creationTime>
<queryURL>
location=08025350&variable=00062&startDate=2010-04-18T14:21:42.169&endDate=2010-04-18T15:12:42.169&period=PT51M&mode=2&token=unknown
</queryURL>
<criteria>
<locationParam>08025350</locationParam>
<variableParam>00062</variableParam>
<timeParam>
<beginDateTime>2010-04-18T14:21:42.169</beginDateTime>
<endDateTime>2010-04-18T15:12:42.169</endDateTime>
</timeParam>
</criteria>
<note title="RequestId">be848300-4b26-11df-8c98-00144f6f9e5a</note>
<note title="DataSource">webnaddeb01</note>
</queryInfo>
<timeSeries name="NWIS Time Series Instantaneous Values">
<sourceInfo xsi:type="SiteInfoType">
<siteName>Toledo Bd Res nr Burkeville, TX</siteName>
<siteCode agencyCode="USGS" siteID="241" network="NWIS">08025350</siteCode>
<geoLocation>
<geogLocation xsi:type="LatLonPointType" srs="EPSG:4326">
<latitude>31.1962984</latitude>
<longitude>-93.5721192</longitude>
</geogLocation>
</geoLocation>
</sourceInfo>
<variable>
<variableCode vocabulary="NWISUV">00062</variableCode>
<variableName>Reservoir elevation</variableName>
<variableDescription>
Elevation of reservoir water surface above datum, feet
</variableDescription>
<dataType>Instantaneous</dataType>
<units unitsType="Flow" unitsAbbreviation="ft"/>
<NoDataValue>-999999</NoDataValue>
</variable>
<values count="1">
<value dateTime="2010-04-18T14:30:00.000-05:00" qualifiers="P">170.64</value>
<qualifier vocabulary="uv_rmk_cd" network="USGS" qualifierCode="P">Provisional data subject to revision.</qualifier>
<method methodID="0">
<MethodDescription>/Reservoir elevation</MethodDescription>
</method>
</values>
</timeSeries>
</timeSeriesResponse>
All i want to do is take the text in "<value dateTime="2010-04-18T14:30:00.000-05:00" qualifiers="P">170.64</value>" and display it in a block on a drupal site.
so when i get it it will look like "The current Lake Level is 170.64 ft"
now i realize that there are 2 good things that can do it and thats the DOM and SimpleXML, but i cant seem to get anything to work.
I am very very new to PHP and any other programming, so please forgive me. I am studying the best i can.
thanks all
I have been fighting this for about 5 days and have gotten nowhere.
i have this url: http://waterservices.usgs.gov/WOF/Insta ... riod=PT51M
which returns this XML:
<timeSeriesResponse xsi:schemaLocation="http://www.cuahsi.org/waterML/1.0/ http://waterservices.usgs.gov/WOF/WaterML-1.0.xsd">
<queryInfo>
<creationTime>2001-01-01T22:22:22</creationTime>
<queryURL>
location=08025350&variable=00062&startDate=2010-04-18T14:21:42.169&endDate=2010-04-18T15:12:42.169&period=PT51M&mode=2&token=unknown
</queryURL>
<criteria>
<locationParam>08025350</locationParam>
<variableParam>00062</variableParam>
<timeParam>
<beginDateTime>2010-04-18T14:21:42.169</beginDateTime>
<endDateTime>2010-04-18T15:12:42.169</endDateTime>
</timeParam>
</criteria>
<note title="RequestId">be848300-4b26-11df-8c98-00144f6f9e5a</note>
<note title="DataSource">webnaddeb01</note>
</queryInfo>
<timeSeries name="NWIS Time Series Instantaneous Values">
<sourceInfo xsi:type="SiteInfoType">
<siteName>Toledo Bd Res nr Burkeville, TX</siteName>
<siteCode agencyCode="USGS" siteID="241" network="NWIS">08025350</siteCode>
<geoLocation>
<geogLocation xsi:type="LatLonPointType" srs="EPSG:4326">
<latitude>31.1962984</latitude>
<longitude>-93.5721192</longitude>
</geogLocation>
</geoLocation>
</sourceInfo>
<variable>
<variableCode vocabulary="NWISUV">00062</variableCode>
<variableName>Reservoir elevation</variableName>
<variableDescription>
Elevation of reservoir water surface above datum, feet
</variableDescription>
<dataType>Instantaneous</dataType>
<units unitsType="Flow" unitsAbbreviation="ft"/>
<NoDataValue>-999999</NoDataValue>
</variable>
<values count="1">
<value dateTime="2010-04-18T14:30:00.000-05:00" qualifiers="P">170.64</value>
<qualifier vocabulary="uv_rmk_cd" network="USGS" qualifierCode="P">Provisional data subject to revision.</qualifier>
<method methodID="0">
<MethodDescription>/Reservoir elevation</MethodDescription>
</method>
</values>
</timeSeries>
</timeSeriesResponse>
All i want to do is take the text in "<value dateTime="2010-04-18T14:30:00.000-05:00" qualifiers="P">170.64</value>" and display it in a block on a drupal site.
so when i get it it will look like "The current Lake Level is 170.64 ft"
now i realize that there are 2 good things that can do it and thats the DOM and SimpleXML, but i cant seem to get anything to work.
I am very very new to PHP and any other programming, so please forgive me. I am studying the best i can.
thanks all