dynamic xml and xmlhttp
Posted: Wed Aug 10, 2005 9:22 pm
Hey everyone. Thanks in advance for any help.
I am trying to use the javascript XMLHTTP object in order to parse XML data. This procedure works fine when I have a static XML document. However, I need to use a dynamically created XML file created through PHP, such as the following:
text_xml.php
When I view this file, it correctly outputs the XML. However, I am unable to parse it using the XMLHTTP object. Is a php dynamically generated XML file somehow different from a static xml file?
Any ideas? Thanks.
Jonathan
I am trying to use the javascript XMLHTTP object in order to parse XML data. This procedure works fine when I have a static XML document. However, I need to use a dynamically created XML file created through PHP, such as the following:
text_xml.php
Code: Select all
class Articles extends DomDocument {
function __construct() {
//has to be called!
parent::__construct();
}
function addArticle($name, $id) {
$item = $this->createElement("university");
$attr1 = $this->createAttribute("name");
$attr1text = $this->createTextNode($name);
$attr1->appendChild($attr1text);
$attr2 = $this->createAttribute("id");
$attr2text = $this->createTextNode($id);
$attr2->appendChild($attr2text);
$item->appendChild($attr1);
$item->appendChild($attr2);
$this->documentElement->appendChild($item);
}
}
$dom = new Articles();
$titlespace = $dom->createElement("schools");
$dom->appendChild($titlespace);
$dom->addArticle('test article','article id');
echo $dom->saveXML();Any ideas? Thanks.
Jonathan