PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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:
<?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>
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.
So, how do I use the DOMXML extension? Do I need to install it as a module? When I do domxml_open_file() it gives me an error saying invalid function.
Thanks
as it's explained in the manual, under the dom xml extension...
you need to install the extension
with the windows version (the zip not the installer) it was as easy as adding: extension=php_domxml.dll to the php.ini file and restarting apache.