DOMXML and XPATH
Posted: Sun Mar 06, 2005 9:33 pm
Hello, I have been working on trying to find good documentation all day and I can't really find anything that is helping me. I have an XML file that contains data about parts of my site and I am trying to query for them, but I can't get XPATH to work with DOMXML. I tried the simple xml extension but I had some problems with that too. Here is what I got:
I get an error that xpath_new_context() is an invalid function. I found that at http://us3.php.net/manual/en/function.x ... ontext.php, but they used a different line for opening the document; however, that line fails for me saying that there is no such function. I am using PHP 5.0.3 (downloaded it today). Any ideas as to what I am doing wrong or what I need to do to fix my problem? Thanks a bunch.
~evlich
Code: Select all
<?php
require_once('ASection.php');
class Site extends ASection {
private $cache_;
private $dom_;
private $xpath_;
public function __construct($fileName) {
$this->dom_ = DOMDocument::load($fileName);
$this->xpath = $this->dom_->xpath_new_context();
$this->cache_ = array();
}
public function getTitle() {
if( isset($this->cache_ї'title']) )
return $this->cache_ї'title'];
return $this->cache_ї'title'] = $this->dom_->xpath('/section/header/title/text()');;
}
// This could have markup
public function getBlurb() {
if( isset($this->cache_ї'blurb']) )
return $this->cache_ї'blurb'];
return $this->cache_ї'blurb'] = $this->dom_->xpath('/section/header/blurb');
}
// This does have markup
public function getContents() {
if( isset($this->cache_ї'contents']) )
return $this->cache_ї'contents'];
return $this->cache_ї'contents'] = $this->dom_->xpath('/section/contents');
}
// This does have markup
public function getMenu() {
if( isset($this->cache_ї'menu']) )
return $this->cache_ї'menu'];
return $this->cache_ї'menu'] = $this->dom_->xpath('/section/menu');
}
public function getNews() {
if( isset($this->cache_ї'news']) )
return $this->cache_ї'news'];
return $this->cache_ї'news'] = $this->dom_->xpath('/section/news');
}
}
?>
<html>
<body>
<?php
//require_once('Site.php');
$site = new Site('SiteTest.xml');
print_r($site->getTitle());
//print_r($site->getBlurb());
//print_r($site->getContents());
?>
</body>
</html>~evlich