]>
Tony Duckles's Git Repositories (git.nynim.org) - delicious-utils.git/blob - delicious-dump/php-delicious/xmlparser.inc.php
2 /***************************************************************/
3 /* XmlParser - part of the PhpDelicious library
5 Software License Agreement (BSD License)
7 Copyright (C) 2005-2008, Edward Eliot.
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 * Neither the name of Edward Eliot nor the names of its contributors
19 may be used to endorse or promote products derived from this software
20 without specific prior written permission of Edward Eliot.
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY
23 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
26 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 Last Updated: 20th January 2008 */
34 /***************************************************************/
37 protected $aXmlResult;
39 public function Parse($sXml) {
40 $this->aXmlResult
= array();
41 $oParser = xml_parser_create();
42 xml_set_object($oParser, $this);
43 xml_set_element_handler($oParser, "StartTag", "CloseTag");
44 xml_set_character_data_handler($oParser, "TagContent");
45 if (!xml_parse($oParser, $sXml)) {
48 xml_parser_free($oParser);
49 return $this->aXmlResult
[0];
52 protected function StartTag($oParser, $sName, $sattributes) {
53 $sTag = array("name" => $sName, "attributes" => $sattributes);
54 array_push($this->aXmlResult
, $sTag);
57 protected function TagContent($oParser, $sTagData) {
58 if (trim($sTagData)) {
59 if (isset($this->aXmlResult
[count($this->aXmlResult
) - 1]['content'])) {
60 $this->aXmlResult
[count($this->aXmlResult
) - 1]['content'] .= $sTagData;
62 $this->aXmlResult
[count($this->aXmlResult
) - 1]['content'] = $sTagData;
67 protected function CloseTag($parser, $name) {
68 $this->aXmlResult
[count($this->aXmlResult
) - 2]['items'][] = $this->aXmlResult
[count($this->aXmlResult
) - 1];
69 array_pop($this->aXmlResult
);