From 1a2e5be242b111566bab580d208dd61b1a1001c2 Mon Sep 17 00:00:00 2001 From: Daniel Neis Araujo Date: Tue, 14 May 2013 17:44:39 -0300 Subject: [PATCH] Just one class for XML responses --- oai2.php | 1 - oai2xml.php | 43 ++++++++++++++----------------------------- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/oai2.php b/oai2.php index 4b467e6..9f5acd7 100644 --- a/oai2.php +++ b/oai2.php @@ -9,7 +9,6 @@ * * It needs other files: * - oaidp-util.php : Utility functions - * - xml_creater.php : XML generating functions * */ diff --git a/oai2xml.php b/oai2xml.php index 3f70ccf..523e7d1 100644 --- a/oai2xml.php +++ b/oai2xml.php @@ -1,6 +1,6 @@ $value) { $request->setAttribute($key,$value); } + + $this->verbNode = $this->addChild($this->doc->documentElement,$this->verb); } function display() { - $pr = new DOMDocument(); - $pr->preserveWhiteSpace = false; - $pr->formatOutput = true; - $pr->loadXML($this->doc->saveXML()); - echo $pr->saveXML(); + $this->doc->formatOutput = true; + $this->doc->preserveWhiteSpace = false; + echo $this->doc->saveXML(); } /** * Add a child node to a parent node on a XML Doc: a worker function. * - * @param $mom_node - * Type: DOMNode. The target node. + * @param $mom_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 - * 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. + * @return DOMElement $added_node * The newly created node */ function addChild($mom_node,$name, $value='') { @@ -52,14 +45,6 @@ class OAI2XML { $added_node = $mom_node->appendChild($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. @@ -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 * - * \param $token Type: string. A random number created somewhere? - * \param $expirationdatetime Type: string. A string representing time. - * \param $num_rows Type: integer. Number of records retrieved. - * \param $cursor Type: string. Cursor can be used for database to retrieve next time. + * @param $token Type: string. A random number created somewhere? + * @param $expirationdatetime Type: string. A string representing time. + * @param $num_rows Type: integer. Number of records retrieved. + * @param $cursor Type: string. Cursor can be used for database to retrieve next time. */ function createResumptionToken($token, $expirationdatetime, $num_rows, $cursor=null) { $resump_node = $this->addChild($this->verbNode,"resumptionToken",$token);