Php.XPath Newbie Problems

Discussion in 'XML' started by Skeets, Feb 16, 2006.

  1. Skeets

    Skeets Guest

    i posted this on alt.comp.php, but, apparently, not many fols are
    parsing xml. i thought i'd try and post it here to see if any xml
    gurus are using php

    i've spent an hour googling and reviewing documentation for phpxml and
    i'm having trouble implementing phpxml..

    i've read

    and it is pretty straight forward stuff... except there is no
    indication how to actually stick the phpxml code within a php file so
    it is usable.

    gives examples, but being a noob to this, it isn't too clear to me...

    i was able to get this to work:

    $x = new XPath( "yourFile.xml" );
    $result = $x->getData("/someElement/elementName");

    but i have no clue how to get these to work:

    1. $tree = $x->exportAsXml("/content[1]/blah[1]");

    what is content? what is blah? how can i print this content and blah
    as xml?

    2. how do i implement the following?


    i tried

    $result = $x->getData('//*[count(ip_address)=1]');
    echo $result;

    and it kicks out the following error:

    XPath error in XPath.class.php:5813 The supplied xPath
    '//*[count(ip_address)=1]' does not *uniquely* describe a node in the
    xml document.Not unique xpath-query, matched 7-times.

    the good news php,xpath appears to understand the code (there are 7
    instances of ip_address in the document), the bad news is that i don't

    the functionality that i *really* want, though, is to be able to count
    a given element directly. count() appears to count those elements with
    a certain number of child elements. i want to count the elements

    can anyone help?

    Skeets, Feb 16, 2006
    1. Advertisements

  2. Skeets wrote:

    > i posted this on alt.comp.php, but, apparently, not many fols are
    > parsing xml.


    If you use PHP 5 then you have XPath support without needing to use that
    package you have found there.

    Or why do you want to use that package, are you using PHP 4?


    Martin Honnen
    Martin Honnen, Feb 16, 2006
    1. Advertisements

  3. Skeets

    Skeets Guest

    martin, i'm using php5. i didn't know any better is the short answer.
    now i do - i appreciate the heads up. i'll review the links and get
    back here if i have any problems.

    thanks for the guidance.
    Skeets, Feb 16, 2006
  4. Skeets

    Skeets Guest

    Skeets, Feb 16, 2006
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
  4. goog
  5. Rajive Narain
    Rajive Narain
    Sep 18, 2009

Share This Page