Just one class for XML responses

This commit is contained in:
Daniel Neis Araujo 2013-05-14 17:44:39 -03:00
parent c5c864f555
commit 1a2e5be242
2 changed files with 14 additions and 30 deletions

View File

@ -9,7 +9,6 @@
* *
* It needs other files: * It needs other files:
* - oaidp-util.php : Utility functions * - oaidp-util.php : Utility functions
* - xml_creater.php : XML generating functions
* *
*/ */

View File

@ -1,6 +1,6 @@
<?php <?php
class OAI2XML { class OAI2XMLResponse {
public $doc; // DOMDocument. Handle of current XML Document object public $doc; // DOMDocument. Handle of current XML Document object
@ -20,31 +20,24 @@ class OAI2XML {
foreach($request_args as $key => $value) { foreach($request_args as $key => $value) {
$request->setAttribute($key,$value); $request->setAttribute($key,$value);
} }
$this->verbNode = $this->addChild($this->doc->documentElement,$this->verb);
} }
function display() { function display() {
$pr = new DOMDocument(); $this->doc->formatOutput = true;
$pr->preserveWhiteSpace = false; $this->doc->preserveWhiteSpace = false;
$pr->formatOutput = true; echo $this->doc->saveXML();
$pr->loadXML($this->doc->saveXML());
echo $pr->saveXML();
} }
/** /**
* Add a child node to a parent node on a XML Doc: a worker function. * Add a child node to a parent node on a XML Doc: a worker function.
* *
* @param $mom_node * @param $mom_node Type: DOMNode. The target node.
* Type: DOMNode. The target node. * @param $name Type: string. The name of child nade is being added
* @param $value Type: string. Text for the adding node if it is a text node.
* *
* @param $name * @return DOMElement $added_node * The newly created node
* Type: string. The name of child nade is being added
*
* @param $value
* Type: string. Text for the adding node if it is a text node.
*
* @return DOMElement $added_node
* The newly created node, can be used for further expansion.
* If no further expansion is expected, return value can be igored.
*/ */
function addChild($mom_node,$name, $value='') { function addChild($mom_node,$name, $value='') {
@ -52,14 +45,6 @@ class OAI2XML {
$added_node = $mom_node->appendChild($added_node); $added_node = $mom_node->appendChild($added_node);
return $added_node; return $added_node;
} }
}
class OAI2XMLResponse extends OAI2XML {
function __construct($verb, $request_args) {
parent::__construct($verb, $request_args);
$this->verbNode = $this->addChild($this->doc->documentElement,$this->verb);
}
/** /**
* Add direct child nodes to verb node (OAI-PMH), e.g. response to ListMetadataFormats. * Add direct child nodes to verb node (OAI-PMH), e.g. response to ListMetadataFormats.
@ -104,10 +89,10 @@ class OAI2XMLResponse extends OAI2XML {
/** /**
* If there are too many records request could not finished a resumpToken is generated to let harvester know * If there are too many records request could not finished a resumpToken is generated to let harvester know
* *
* \param $token Type: string. A random number created somewhere? * @param $token Type: string. A random number created somewhere?
* \param $expirationdatetime Type: string. A string representing time. * @param $expirationdatetime Type: string. A string representing time.
* \param $num_rows Type: integer. Number of records retrieved. * @param $num_rows Type: integer. Number of records retrieved.
* \param $cursor Type: string. Cursor can be used for database to retrieve next time. * @param $cursor Type: string. Cursor can be used for database to retrieve next time.
*/ */
function createResumptionToken($token, $expirationdatetime, $num_rows, $cursor=null) { function createResumptionToken($token, $expirationdatetime, $num_rows, $cursor=null) {
$resump_node = $this->addChild($this->verbNode,"resumptionToken",$token); $resump_node = $this->addChild($this->verbNode,"resumptionToken",$token);