Reading XML Help
Posted: Sun Feb 10, 2008 10:02 pm
Hello! First post for me here. I'm very new to PHP and programming in general (1 month, actually, for both), but I'm learning faster than I expected.
I've figured out how to read and add elements to an xml file--but only what the tutorials have shown me i.e.:
That's nice, but I have to know the position of the movie element [0] to list all of it's element values.
I am going to be making regularly updating an xml file with every main element having an attribute that is a date stamp.
i.e.
Obviously the first entry is [0] and the second [1], so to display their contents I could simply point to [0] or [1]. But I'd rather it figured it out on its own. If I know the date stamp I'm looking for and plop it into a variable, how can I get it to figure out which number [0] or [1] on the tree that is, and therefore use the variable to find the parent element in the xml file to display it's contents?
Thanks so much in advance. If I wasn't clear please ask for clarification.
If I'm too new for this forum, please put my email address on some spam list and torch this post.
I've figured out how to read and add elements to an xml file--but only what the tutorials have shown me i.e.:
Code: Select all
$xml = new SimpleXMLElement('new.xml', null, true);
foreach ($xml->movie[0]->characters->character as $c) {
echo $c->name, ' - played by: ';
echo $c->actor, '<br />';
}I am going to be making regularly updating an xml file with every main element having an attribute that is a date stamp.
i.e.
Code: Select all
<entries>
<entry date="2008_02_02_15_56">
<blah>Blah blah</blah>
<blah2>Blah blah</blah2>
</entry>
<entry date="2008_02_07_12_23">
<blah>Blah blah</blah>
<blah2>Blah blah</blah2>
</entry>
</entries>
Thanks so much in advance. If I wasn't clear please ask for clarification.
If I'm too new for this forum, please put my email address on some spam list and torch this post.