Page 1 of 1

DOMXML

Posted: Wed Oct 02, 2002 12:45 am
by Davey
OK... I'm trying to learn how to use DOM.
Unfortunately... it's just NOT getting through. I've read a few tutorials... but they're old and well, I've gotten lost.

What I need is either a bang up-to-date tutorial, OR someone to supply with some PHP code which I can pick apart. I need to parse XML to get what attributes exist in a node, the attribute values, and to like... "select" certain nodes based on an attributes value. All my XML is like this:

Code: Select all

<data attr1="val1" attr2="val2 />
rather than:

Code: Select all

<date>
<attr1>val1</attr1>
<attr2>val2</attr2>
</date>
- Davey

Posted: Wed Oct 02, 2002 8:10 am
by volka
do you want to know how to do it in general or how to in php?
if the latter (which is more likely since your post is in the php-forum ;) )take a look at CV. XML parser functions and (probably more of interest) xml_set_element_handler where you can specifiy a start_element_handler ( resource parser, string name, array attribs) function.
Depending on what you want to achieve CVII. XSLT functions might be thrilling, too.

Posted: Fri Oct 04, 2002 4:34 pm
by Davey
Thanks for your response... I *really* want to use DOM for this.... I have read and considered the merits of SAX, DOM and PRAX and DOM is my choice... I just need to get my head around it.

- Davey

Posted: Fri Oct 04, 2002 5:57 pm
by volka
then I suggest http://www.xmlfiles.com/ and (not a tutorial page) http://www.w3.org/TR/

keep in mind [http://www.php.net/manual/en/ref.domxml.php]
The DOM XML extension has been overhauled in PHP 4.3.0 to better comply with the DOM standard. The extension still contains many old functions, but they should no longer be used. In particular, functions that are not object-oriented should be avoided.