How to parse via PHP '<item id=12>'



Hi.

Working with 4.3.11, I'm trying to parse an XML document:
------------
<doc>
<item id=1>Richard</item>
<item id=2>Mary</item>
</doc>
----------
I'm trying to get '1' and '2'

If I want to get 'Richard' or 'Mary' I use:
----------
xml_set_element_handler($parser, "open_tag", "close_tag");
xml_set_character_data_handler($parser, "tag_contents");

function close_tag($parser, $name)
{
global $contents;
$contents = trim($contents);
switch($name)
{
case "ITEM":
print("$contents\n");
break;
}
}
-------------------

But no idea about getting '1' or '2'. Any suggestion?

.



Relevant Pages

  • Re: XML in XHTML
    ... my solution was to read in the xml document using ... xmlhttprequest, then to parse it from there. ... Prev by Date: ...
    (comp.lang.javascript)
  • Re: XML in XHTML
    ... my solution was to read in the xml document using ... xmlhttprequest, then to parse it from there. ... Prev by Date: ...
    (comp.text.xml)
  • Creating a booking engine with Web Services
    ... Then I get an xml base response from the web service. ... So XSLT will help me parse the data, I also want to use that data i parse ... They respond back with an XML document. ... Then the customer will pick a flight ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • SAX and file chooser
    ... How can I use SAX to parse an XML document which has been selected ... using a file chooser? ... I want to use an InputSource for the XMLReader to ... XML document. ...
    (comp.lang.java.programmer)
  • Re: TCL Dom question
    ... > methods from there to parse the XML document, ... I'd like to load directly from a file location ... set ifd ...
    (comp.lang.tcl)