Re: [PHP] Good XML Parser

[email protected] ("Waynn Lue")
Newsgroups php.general
Message-ID <[email protected]>
So if I'm looking to parse certain attributes out of an XML tree, if I
use SAX, it seems that I would need to keep track of state internally.
 E.g., if I have a tree like

<head>
 <a>
   <b></b>
  </a>
  <a>
    <b></b>
  </a>
</head>

and say I'm interested in all that's between <b> underneath any <a>,
I'd need to have a state machine that looked for an <a> followed by a
<b>.  If I'm doing that, though, it seems like I should just start
using a DOM parser instead?

Thanks for any insight,
Waynn

On Mon, May 12, 2008 at 1:29 AM, David Otton
<[email protected]> wrote:
> 2008/5/12 Waynn Lue <[email protected]>:
>
> > What's the best way to pull down XML from a URL?  fopen($URL), then
>  > using xml_parse?  Or should I be using XML_Parser or SimpleXML?
>
>  XML parsers fall into two general camps - DOM and SAX. DOM parsers
>  represent an entire XML document as a tree, in-memory, when they are
>  first instantiated. They are generally more memory-hungry and take
>  longer to instantiate, but they can answer queries like "what is the
>  path to this node" or "give me the siblings of this node".
>
>  SAX parsers are stream- or event-based, and are much more lightweight
>  - they parse the XML in a JIT fashion, and can't answer much more than
>  "give me the next node".
>
>  If you just need the data, a SAX parser will probably do everything
>  you need. If you need the tree structure implicit in an XML document,
>  use a DOM parser. Expat, which XML Parser
>  (http://uk3.php.net/manual/en/book.xml.php) is based on, is a SAX
>  parser. DOM XML (http://uk3.php.net/manual/en/book.domxml.php) is,
>  obviously, a DOM parser. I don't know, off the top of my head, which
>  camp SimpleXML falls into.
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.