Re: [PHP] Simple XML, (x)html, and xpath

2012-05-25 Thread Andrew Ballard
On Fri, May 25, 2012 at 3:57 AM, Gary  wrote:
> If I use simplexml_load_string to create an XML object with the
> following XHTML
> ,
> | 
> |  | "http://www.w3.org/TR/
> | xhtml1/DTD/xhtml1-strict.dtd">
> | http://www.w3.org/1999/xhtml";>
> |  | />
> | test title
> | 
> | 
> | 
> | 
> | 
> `
>
> I get this SimpleXMLElement back
> ,
> | object(SimpleXMLElement)#1 (2) {
> |   ["head"]=>
> |   object(SimpleXMLElement)#2 (1) {
> |     ["title"]=>
> |     string(10) "test title"
> |   }
> |   ["body"]=>
> |   object(SimpleXMLElement)#3 (1) {
> |     ["comment"]=>
> |     object(SimpleXMLElement)#4 (0) {
> |     }
> |   }
> | }
> `
>
> but I cannot seem to get anything out of an xpath expression, no matter
> what I try.
>
> If, however, I remove the 'xmlns="http://www.w3.org/1999/xhtml";' in the
> html element, it works fine. So yeah, I can just remove that text,
> but... is there something wrong here, in my expectation or in the xpath
> function?
>
> TIA.
>
> --
> Gary        Please do NOT send me 'courtesy' replies off-list.

Gary,

I am not sure what you have tried, but namespaces change everything in
XPath compared to documents without them. This isn't exact, but XPath
without namespaces is often simple such as:

/html/head/title

Once you add a namespace, though, the XPath becomes something like

/*[namespace-uri()='http://www.w3.org/1999/xhtml' and
local-name()='html']/*[namespace-uri()='http://www.w3.org/1999/xhtml'
and local-name()='head']/*[namespace-uri()='http://www.w3.org/1999/xhtml'
and local-name()='title']


(I'm not sure of the exact syntax since I don't have something open
right now that I can test it in.

However, I think SimpleXML has some features that make this easier.
Take a look at this:

http://www.php.net/manual/en/simplexmlelement.registerxpathnamespace.php

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple XML, (x)html, and xpath

2012-05-25 Thread ma...@behnke.biz


Gary  hat am 25. Mai 2012 um 09:57
geschrieben:

> If I use simplexml_load_string to create an XML object with the
> following XHTML
> ,
> | 
> |  | "http://www.w3.org/TR/
> | xhtml1/DTD/xhtml1-strict.dtd">
> | http://www.w3.org/1999/xhtml";>
> |  | />
> | test title
> | 
> | 
> | 
> | 
> | 
> `
>
> I get this SimpleXMLElement back
> ,
> | object(SimpleXMLElement)#1 (2) {
> |   ["head"]=>
> |   object(SimpleXMLElement)#2 (1) {
> | ["title"]=>
> | string(10) "test title"
> |   }
> |   ["body"]=>
> |   object(SimpleXMLElement)#3 (1) {
> | ["comment"]=>
> | object(SimpleXMLElement)#4 (0) {
> | }
> |   }
> | }
> `
>
> but I cannot seem to get anything out of an xpath expression, no matter
> what I try.
>
> If, however, I remove the 'xmlns="http://www.w3.org/1999/xhtml";' in the
> html element, it works fine. So yeah, I can just remove that text,
> but... is there something wrong here, in my expectation or in the xpath
> function?


Maybe you can show us your xpath expression?


>
> TIA.
>
> --
> GaryPlease do NOT send me 'courtesy' replies off-list.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php