I'm trying to parse an XML formatted post reply, and I can't figure
out how to get the value of the right tag.
The XML is formatted like this:
<A>
<foo>val1</foo>
</A>
<B>
<foo>val2</foo>
</B>
<BAR>
val3
</BAR>
I need the value of A's "foo", not B's "foo". But from what I can find
I can only get the value of the lowest nested tag in a nest. i.e.:
"foo" or "BAR". Not specifically A or B's "foo".
Below is the script I'm using. In this case "TOTALCHARG ES" is the
"foo" I'm looking for, but I need it to specifically get A's and not
B's.
If someone can point me to where I can find out how, I'd appreciate
it!
-Liam
//Defines startElement function
function startElement($x ml_parser, $element_name, $element_attrs) {
global $printout, $tag, $output1;
switch($element _name) {
case "TOTALCHARG ES":
$printout = true;
$tag = "TOTALCHARG ES";
break;
}
}
//Defines endElement function
function endElement($xml _parser, $element_name) {
global $printout, $tag, $output1;
switch($element _name) {
case "TOTALCHARG ES":
$printout = false;
$tag = "";
break;
}
}
//Defines characterData function
function characterData($ xml_parser, $fp) {
global $printout, $tag, $output1;
if (($tag=="TOTALC HARGES") && ($printout==tru e)) {
$output1 = $fp;
//echo $output;
}
return $output1;
}
out how to get the value of the right tag.
The XML is formatted like this:
<A>
<foo>val1</foo>
</A>
<B>
<foo>val2</foo>
</B>
<BAR>
val3
</BAR>
I need the value of A's "foo", not B's "foo". But from what I can find
I can only get the value of the lowest nested tag in a nest. i.e.:
"foo" or "BAR". Not specifically A or B's "foo".
Below is the script I'm using. In this case "TOTALCHARG ES" is the
"foo" I'm looking for, but I need it to specifically get A's and not
B's.
If someone can point me to where I can find out how, I'd appreciate
it!
-Liam
//Defines startElement function
function startElement($x ml_parser, $element_name, $element_attrs) {
global $printout, $tag, $output1;
switch($element _name) {
case "TOTALCHARG ES":
$printout = true;
$tag = "TOTALCHARG ES";
break;
}
}
//Defines endElement function
function endElement($xml _parser, $element_name) {
global $printout, $tag, $output1;
switch($element _name) {
case "TOTALCHARG ES":
$printout = false;
$tag = "";
break;
}
}
//Defines characterData function
function characterData($ xml_parser, $fp) {
global $printout, $tag, $output1;
if (($tag=="TOTALC HARGES") && ($printout==tru e)) {
$output1 = $fp;
//echo $output;
}
return $output1;
}
Comment