Name of the tag--in the "the" above, this is the tag STORY, and
Below that byline. You want byline_author. You want the "the". The
The ' is ' index [0] in the second part of the two-dimensional array.
Even if there is only *one* byline author, it's still an array, and you
Still have to use the [0]. Now, the two-dimensional array is storing
Dynamic structures-objects in the case. So, we need to dereference
The object, hence the. The Byline_author is the tag for you want, and it
is a array in that object. The reason for the "array is" if there are
More than one byline_author for the tags STORY, byline, we would have a
[0] and [1] in the array. In your case there is just the one.
This is very confusing, I know, but once your understand it, the power
The This method is more apparent. Have access to *every* bit of
Information in the XML file, without has to do anything but understand
How to refer to the variables. ***
EVERY variable would look like this:
Print $xml ["Story_byline"][0]->byline_author[0];
The trick is understanding the variable to give
Information. This is an array of arrays of objects holding arrays!
Any tag that has attributes would have them stored in a special object
Array named "Attributes" and'll is called this way:
Print $xml ["STORY"][0]->attributes[0]["TIMESTAMP"];
If you are aren ' t sure if there are attributes, you could do isset () or
Is_array () for that above example. If isset (), could for loop and
while (the list ($k, $v) = each ($xml ...)) over it and get the values.
Array of
Objects
|
|
$xml ["Story_byline"][0]->byline_author[0];
^ ^
Array of ^
Arrays ^
^
Array in
Object
In general, to get the value of this:
<STATE>
<STATENAME></STATENAME>
<COUNTY>
<COUNTYNAME></COUNTYNAME>
<CITY></CITY>
<CITY></CITY>
</COUNTY>
<COUNTY>
<COUNTYNAME></COUNTYNAME>
<CITY></CITY>
<CITY></CITY>
</COUNTY>
</STATE>
You would look for what you want, say "City", the then go up one level, to
COUNTY (Countyname is on the same "level") for your:
$xml ["State_county"]--all tags pushed together are separated with
"_". Otherwise tags are as they were-spaces, dashes, case, etc.
Now, you want the the ' COUNTY, though there are two, so we are doing this:
$xml ["State_county"][0]--to get the second, we ' d use [1] instead of
[0]. You could also does a for () loop through it, the using sizeof () to figure
Out how big it is.
So, we have the state,county we want--the one. It ' s an
object, and we know we want the city. So, we dereference the object. The
Name of the array we want is, of course, City:
$xml ["State_county"][0]->city[0] (the one, the second one would be
[1]).
And that ' s it. Basically, find what your want, and go up a level.
You could did some complex for loops to go through all them:
For ($i =0 $i <sizeof ($xml ["State_county"]); $i + +) {
For ($j =0 $j <sizeof ($xml ["State_county"][0]->city); $j + +) {
Print $xml ["State_county"] [$i]->city[$j];
}
}
-----------
Whew. I hope that helps, not hurts.
*/
/* Used to store the parsed information * *
Class Xml_container {
function Store ($k, $v) {
$this->{$k}[] = $v;
}
}
* * Parses the information * *
Class XML {
Initialize some variables
var $current _tag=array ();
var $xml _parser;
var $Version = 1.0;
var $tagtracker = array (); -->