Re: Urgent: Way to XML-parse data with <f n="name"> </f> tags?
| From: | Myron Turner | Date: | Thu, 08 Mar 2007 16:57:11 +0000 |
| Subject: | Re: Urgent: Way to XML-parse data with <f n="name"> </f> tags? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-250086@lists.php.net to get a copy of this message | ||
Rob Gould wrote:
The problem I'm having is that the XML data that comes back from the host doesn't just have <eventname> </eventname> tags. It has <f n="eventname">datahere</f> tags, and I don't know how to get the XML parser to read the values using that format. (And I don't have control over the host) As a first step, I just want to retrieve the "eventname", "venuename", and "venuecity" data from within the "result" tags at the bottom of the data.
I'm really hoping this is possible with PHP - - - can someone please steer me in the right direction and tell my what I should change in the below script? The $tag value is not getting a value string, due to the XML-data....
Here's my present script:
<?php
$insideitem = false;
$tag = "";
$eventname = "";
$venuename = "";
$venuecity = "";
function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $eventname, $venuename, $venuecity;
if ($insideitem) {
$tag = $name;
} elseif ($name == "RESULT") {
echo "found result";
$insideitem = true;
}
}
?>
You'll get these from the attributes array, which is an associative array:
The third parameter, /attribs/, contains an associative array with
the element's attributes (if any).The keys of this array are the
attribute names, the values are the attribute values.Attribute names
are case-folded
<http://www.php.net/manual/en/ref.xml.php#xml.case-folding> on the
same criteria as element names.Attribute values are /not/ case-folded.
From: http://www.php.net/manual/en/function.xml-set-element-handler.php
So $venuecity - $attrs['venuecity'], etc.
--PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php-- _____________________ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/