PHP - XML xpath function - Search for value

I’ve read various post and tried various solutions, but until now, I don’t know how to use the xpath function for my goal.

I’ve a XML file, that looks like this:

[code]<?xml version="1.0" encoding="iso-8859-1"?>

History
History Paragraph 1 until 7
Other documents…[/code]
I need an PHP script that finds out if a my XML file contains a variable.

Example (how it should function, but this is not a working script):

[php]function xmlcontain($docname){
//Load XML file
$xmlfile = ‘users/’.$_SESSION[‘usr’].’/downloaded.xml’;
$xml = XMLload->($xmlfile);

//Whether the XML file contains an element named ‘document’, with the value of $docname
if($xml contains $xml->’/document’->value[$docname]){
//If it does contain…
return 1;
} else {
//If it doesn’t…
return 0;
}

}[/php]
Notice that my XML file is located in ‘/users/[username]/downloaded.xml’, while my script is ‘download.php’.

I also want that if I use the function to search for “History”, and when there isn’t a document “History”, but “History Paragraph 1 until 7” is there, it will returns 0.

Because “History Paragraph 1 until 7” does contain “History”, but it isn’t equal to “History”

Please help,

Thank you,

Isaiah

P.S. I hope I was clear enough.

Have you seen the SimpleXML functions? Here’s basic usage examples:

http://www.php.net/manual/en/simplexml.examples-basic.php

Sponsor our Newsletter | Privacy Policy | Terms of Service