PHP 5 & DomXpath

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Janwillem Borleffs

    #1

    PHP 5 & DomXpath

    Hello,

    When I use the followng code:

    $dom = new domDocument;
    $dom->load($xml);
    $xpath = new domXPath($dom);
    $results = $xpath->query('/');

    I get the following error message on the last line:

    Warning: Invalid XPath Context in [...] on line [...]

    I have a feeling I can fix this problem by calling:

    $xpath->registerNamesp ace();

    but am unsure about which arguments to use.

    Thanks In Advance for any pointers.


    Regards,
    JW

  • DrTebi

    #2
    Re: PHP 5 & DomXpath

    On Mon, 19 Jul 2004 16:46:05 +0200, Janwillem Borleffs wrote:
    [color=blue]
    > Hello,
    >
    > When I use the followng code:
    >
    > $dom = new domDocument;
    > $dom->load($xml);
    > $xpath = new domXPath($dom);
    > $results = $xpath->query('/');
    >
    > I get the following error message on the last line:
    >
    > Warning: Invalid XPath Context in [...] on line [...]
    >
    > I have a feeling I can fix this problem by calling:
    >
    > $xpath->registerNamesp ace();
    >
    > but am unsure about which arguments to use.
    >
    > Thanks In Advance for any pointers.
    >
    >
    > Regards,
    > JW[/color]

    I am running PHP Version 5.0.0 on Gentoo Linux with Apache2. I tried
    exactly the code you posted with my "cdcatalog. xml" (which is actually on
    www.w3schools.com), and did not get any warning or errors. I have my error
    reporting set to E_ALL.

    When I do this afterwards:
    print_r($result s);
    it returns:
    DOMNodeList Object ( )
    meaning everything went alright.

    Maybe there is something wrong with the XML?

    DrTebi


    Comment

    • Janwillem Borleffs

      #3
      Re: PHP 5 & DomXpath

      DrTebi wrote:[color=blue]
      > Maybe there is something wrong with the XML?
      >[/color]

      Nope, the bug is in the zend.ze1_compat ibility_mode directive. When you
      enable it in the php.ini file, the problem occurs.


      JW



      Comment

      Working...