[UPHPU] beginner to DOM library

Jared Stevens jareds at brightbuilders.com
Wed Nov 8 11:11:40 MST 2006


When I was messing with the DOM, I was having a similar problem. I had
to register a namespace to make XPath  work. I don't know if this is
required though. I was able to use the getElementByTagName and like
calls just fine without the registered namespace.

To be honest though, this may sound backward, but the DOM libraries in
PHP don't seem intuitive enough, (or the documentation is bad or
something). I'm also not sure if it was my fault or what, but I've also
had what appeared to be memory leaks with the new DOM parser as well.
(When I'm parsing a high volume of XML).

I've been very tempted on many occasions to just parse everything with
regular expressions and be done with it.

Jared Stevens
-BrightBuilders-

Richard K Miller wrote:
> I'm trying to get acquainted with the PHP DOM library (php.net/dom)
> available in PHP5.  Any idea why I don't get more meaningful output
> from this code?
>
> <?php
>
> $doc = new DOMDocument;
> $doc->loadXML('<?xml version="1.0" encoding="iso-8859-1"
> ?><foo><bar>hello world</bar></foo>');
> print_r($doc);
>
> $xpath = new DOMXPath($doc);
> print_r($xpath);
>
> $nodes = $xpath->query("//foo");
> print_r($nodes);
>
> foreach($nodes as $node)
>     print_r($node);
>
> ?>
>
> OUTPUT:
>
> DOMDocument Object
> (
> )
> DOMXPath Object
> (
> )
> DOMNodeList Object
> (
> )
> DOMElement Object
> (
> )
>
> I was hoping the output would include various nodes in the document. 
> Maybe PHP is masking the values from print_r()?
>
> Richard
>
>
>
> _______________________________________________
>
> UPHPU mailing list
> UPHPU at uphpu.org
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net


More information about the UPHPU mailing list