- Extending Zend_Service for Amazon BrowseNodes, Ancestors are not processed
- <BrowseNodes>
- <BrowseNode>
- <BrowseNodeId>10605</BrowseNodeId>
- <Name>Education</Name>
- <Children>...</Children>
- <Ancestors>
- <BrowseNode>
- <BrowseNodeId>21</BrowseNodeId>
- <Name>Education & Reference</Name>
- <Ancestors>
- <BrowseNode>
- <BrowseNodeId>1000</BrowseNodeId>
- <Name>Subjects</Name>
- <IsCategoryRoot>1</IsCategoryRoot>
- <Ancestors>
- <BrowseNode>
- <BrowseNodeId>283155</BrowseNodeId>
- <Name>Books</Name>
- </BrowseNode>
- </Ancestors>
- </BrowseNode>
- </Ancestors>
- </BrowseNode>
- </Ancestors>
- </BrowseNode>
- </BrowseNodes>
- class Zend_Service_Amazon_Item
- {
- /**
- * @var array
- */
- public $BrowseNodes = array();
- public function __construct($dom) {
- // .... the code for the other items
- // .... for browsenode
- $result = $xpath->query('./az:BrowseNodes/*', $dom);
- if ($result->length > 1) {
- /**
- * @see Zend_Service_Amazon_BrowseNode
- */
- require_once 'Zend/Service/Amazon/BrowseNode.php';
- foreach ($result as $r) {
- $this->BrowseNodes[] = new Zend_Service_Amazon_BrowseNode($r);
- }
- }
- }
- }
- class Zend_Service_Amazon_BrowseNode
- {
- /**
- * @var integer
- */
- public $BrowseNodeId;
- /**
- * @var string
- */
- public $Name;
- /**
- * @var boolean
- */
- public $IsCategoryRoot;
- /**
- * @var array BrwoserNodes
- */
- public $Ancestors = array();
- /**
- * @var string
- */
- public $Children = array();
- /**
- * Assigns values to properties relevant to BrowseNode
- *
- * @param DOMElement $dom
- * @return void
- */
- public function __construct(DOMElement $dom)
- {
- $xpath = new DOMXPath($dom->ownerDocument);
- $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2011-08-01');
- foreach (array('BrowseNodeId', 'Name') as $el) {
- $result = $xpath->query("./az:$el/text()", $dom);
- if ($result->length == 1) {
- $this->$el = (string) $result->item(0)->data;
- }
- }
- $result = $xpath->query('./az:IsCategoryRoot/text()', $dom);
- if ($result->length == 1) {
- $this->IsCategoryRoot = (bool) $result->item(0)->data ;
- }
- foreach (array('Children','Ancestors') as $el) {
- $result = $xpath->query("./$el/*", $dom);
- if ($result->length > 1) {
- foreach ($result as $r) {
- array_push($this->$el, new Zend_Service_Amazon_BrowseNode($r));
- }
- }
- }
- }
- }
- $result = $xpath->query("./$el/*", $dom);
- $result = $xpath->query("./az:$el/*", $dom);
- if ($result->length > 1) {
- if ($result->length > 0) {
- foreach (array('Children','Ancestors') as $el) {
- $result = $xpath->query("./az:$el/*", $dom);
- if ($result->length > 0) {
- foreach ($result as $r) {
- array_push($this->$el, new Zend_Service_Amazon_BrowseNode($r));
- }
- }
- }