Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Php.XPath Newbie Problems

Reply
Thread Tools

Php.XPath Newbie Problems

 
 
Skeets
Guest
Posts: n/a
 
      02-16-2006
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

http://www.zvon.org/xxl/XPathTutoria.../examples.html

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.

http://jm3.net/misc/php-xpath-quickstart/

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?

//*[count(BBB)=2]

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
directly.

can anyone help?

tia...

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      02-16-2006


Skeets wrote:

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


> http://jm3.net/misc/php-xpath-quickstart/


If you use PHP 5 then you have XPath support without needing to use that
package you have found there.
<http://www.php.net/manual/en/function.dom-domxpath-construct.php>
<http://www.php.net/manual/en/function.dom-domxpath-query.php>

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

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Skeets
Guest
Posts: n/a
 
      02-16-2006
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.

 
Reply With Quote
 
Skeets
Guest
Posts: n/a
 
      02-16-2006
i haven't tried it yet, but this seems to answer my question regarding
how to count formelements using php5.

http://www.php.net/manual/en/functio...h-evaluate.php

the xml data set is here:

http://www.php.net/manual/en/ref.dom.php

i don't understand the syntax yet, but that will likely come with some
more study.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems, problems for newbie Shelly ASP .Net 1 09-03-2007 02:10 AM
VONAGE Newbie w/newbie question New_kid@nowhere.new VOIP 0 08-11-2007 01:40 PM
another newbie question from another newbie.... Lee UK VOIP 4 05-17-2005 04:10 PM
newbie: cisco vlan newbie question No Spam Cisco 3 06-07-2004 10:02 AM
Newbie! I'm a newbie! What's wrong with this program? Id0x Python 4 07-20-2003 11:40 PM



Advertisments