annotate cake/libs/xml.php @ 0:261e66bd5a0c

hg init
author Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
date Sun, 24 Jul 2011 21:08:31 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 <?php
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 * XML handling for Cake.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 * The methods in these classes enable the datasources that use XML to work.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 * PHP versions 4 and 5
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 * Licensed under The MIT License
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 * Redistributions of files must retain the above copyright notice.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 * @link http://cakephp.org CakePHP(tm) Project
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 * @package cake
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 * @subpackage cake.cake.libs
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 * @since CakePHP v .0.10.3.1400
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 App::import('Core', 'Set');
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 * XML node.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 * Single XML node in an XML tree.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 * @package cake
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 * @subpackage cake.cake.libs
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 * @since CakePHP v .0.10.3.1400
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 class XmlNode extends Object {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 * Name of node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 * @var string
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 var $name = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 * Node namespace
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 * @var string
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 var $namespace = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 * Namespaces defined for this node and all child nodes
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 * @var array
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 var $namespaces = array();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 * Value of node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 * @var string
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 var $value;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 * Attributes on this node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 * @var array
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 var $attributes = array();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 * This node's children
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 * @var array
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 var $children = array();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 * Reference to parent node.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 * @var XmlNode
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 * @access private
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 var $__parent = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 * Constructor.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 * @param string $name Node name
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 * @param array $attributes Node attributes
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 * @param mixed $value Node contents (text)
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 * @param array $children Node children
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 function __construct($name = null, $value = null, $namespace = null) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 if (strpos($name, ':') !== false) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 list($prefix, $name) = explode(':', $name);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 if (!$namespace) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 $namespace = $prefix;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 $this->name = $name;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 if ($namespace) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 $this->namespace = $namespace;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 if (is_array($value) || is_object($value)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 $this->normalize($value);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 } elseif (!empty($value) || $value === 0 || $value === '0') {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 $this->createTextNode($value);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 * Adds a namespace to the current node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 * @param string $prefix The namespace prefix
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 * @param string $url The namespace DTD URL
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 * @return void
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 function addNamespace($prefix, $url) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 if ($ns = Xml::addGlobalNs($prefix, $url)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 $this->namespaces = array_merge($this->namespaces, $ns);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 return true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 * Adds a namespace to the current node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 * @param string $prefix The namespace prefix
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 * @param string $url The namespace DTD URL
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 * @return void
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 function removeNamespace($prefix) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 if (Xml::removeGlobalNs($prefix)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 return true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 * Creates an XmlNode object that can be appended to this document or a node in it
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 * @param string $name Node name
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 * @param string $value Node value
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 * @param string $namespace Node namespace
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 * @return object XmlNode
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 function &createNode($name = null, $value = null, $namespace = false) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 $node =& new XmlNode($name, $value, $namespace);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 $node->setParent($this);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 return $node;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 * Creates an XmlElement object that can be appended to this document or a node in it
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 * @param string $name Element name
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 * @param string $value Element value
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 * @param array $attributes Element attributes
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 * @param string $namespace Node namespace
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 * @return object XmlElement
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 function &createElement($name = null, $value = null, $attributes = array(), $namespace = false) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 $element =& new XmlElement($name, $value, $attributes, $namespace);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 $element->setParent($this);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 return $element;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 * Creates an XmlTextNode object that can be appended to this document or a node in it
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 * @param string $value Node value
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 * @return object XmlTextNode
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 function &createTextNode($value = null) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 $node = new XmlTextNode($value);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 $node->setParent($this);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 return $node;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 * Gets the XML element properties from an object.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 * @param object $object Object to get properties from
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 * @return array Properties from object
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 function normalize($object, $keyName = null, $options = array()) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 if (is_a($object, 'XmlNode')) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 return $object;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 $name = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 $options += array('format' => 'attributes');
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 if ($keyName !== null && !is_numeric($keyName)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 $name = $keyName;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 } elseif (!empty($object->_name_)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 $name = $object->_name_;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 } elseif (isset($object->name)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 $name = $object->name;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 } elseif ($options['format'] == 'attributes') {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 $name = get_class($object);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 $tagOpts = $this->__tagOptions($name);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 if ($tagOpts === false) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 return;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 if (isset($tagOpts['name'])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 $name = $tagOpts['name'];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 } elseif ($name != strtolower($name) && $options['slug'] !== false) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 $name = Inflector::slug(Inflector::underscore($name));
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 if (!empty($name)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 $node =& $this->createElement($name);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 $node =& $this;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 $namespace = array();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 $attributes = array();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 $children = array();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 $chldObjs = array();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 if (is_object($object)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 $chldObjs = get_object_vars($object);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 } elseif (is_array($object)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 $chldObjs = $object;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 } elseif (!empty($object) || $object === 0 || $object === '0') {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 $node->createTextNode($object);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 $attr = array();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 if (isset($tagOpts['attributes'])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 $attr = $tagOpts['attributes'];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 if (isset($tagOpts['value']) && isset($chldObjs[$tagOpts['value']])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 $node->createTextNode($chldObjs[$tagOpts['value']]);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 unset($chldObjs[$tagOpts['value']]);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 $n = $name;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 if (isset($chldObjs['_name_'])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 $n = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 unset($chldObjs['_name_']);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 $c = 0;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 foreach ($chldObjs as $key => $val) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 if (in_array($key, $attr) && !is_object($val) && !is_array($val)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 $attributes[$key] = $val;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 if (!isset($tagOpts['children']) || $tagOpts['children'] === array() || (is_array($tagOpts['children']) && in_array($key, $tagOpts['children']))) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 if (!is_numeric($key)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 $n = $key;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 if (is_array($val)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 foreach ($val as $n2 => $obj2) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 if (is_numeric($n2)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 $n2 = $n;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 $node->normalize($obj2, $n2, $options);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 if (is_object($val)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 $node->normalize($val, $n, $options);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 } elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 $tmp =& $node->createElement($key);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 if (!empty($val) || $val === 0 || $val === '0') {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 $tmp->createTextNode($val);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 } elseif ($options['format'] == 'attributes') {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 $node->addAttribute($key, $val);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 $c++;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 if (!empty($name)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 return $node;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 return $children;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 * Gets the tag-specific options for the given node name
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 * @param string $name XML tag name
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 * @param string $option The specific option to query. Omit for all options
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 * @return mixed A specific option value if $option is specified, otherwise an array of all options
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 * @access private
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 function __tagOptions($name, $option = null) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 if (isset($this->__tags[$name])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 $tagOpts = $this->__tags[$name];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 } elseif (isset($this->__tags[strtolower($name)])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 $tagOpts = $this->__tags[strtolower($name)];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 return null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 if ($tagOpts === false) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 if (empty($option)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 return $tagOpts;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 if (isset($tagOpts[$option])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 return $tagOpts[$option];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 return null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 * Returns the fully-qualified XML node name, with namespace
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 function name() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 if (!empty($this->namespace)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 $_this =& XmlManager::getInstance();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 if (!isset($_this->options['verifyNs']) || !$_this->options['verifyNs'] || in_array($this->namespace, array_keys($_this->namespaces))) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 return $this->namespace . ':' . $this->name;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 return $this->name;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
338
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 * Sets the parent node of this XmlNode.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 function setParent(&$parent) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 if (strtolower(get_class($this)) == 'xml') {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 return;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 if (isset($this->__parent) && is_object($this->__parent)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 if ($this->__parent->compare($parent)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 return;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 foreach ($this->__parent->children as $i => $child) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 if ($this->compare($child)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 array_splice($this->__parent->children, $i, 1);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 break;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 if ($parent == null) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 unset($this->__parent);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 $parent->children[] =& $this;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 $this->__parent =& $parent;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 * Returns a copy of self.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 * @return object Cloned instance
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 function cloneNode() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 return clone($this);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 * Compares $node to this XmlNode object
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 * @param object An XmlNode or subclass instance
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 * @return boolean True if the nodes match, false otherwise
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 function compare($node) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 $keys = array(get_object_vars($this), get_object_vars($node));
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 return ($keys[0] === $keys[1]);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 * Append given node as a child.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 * @param object $child XmlNode with appended child
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 * @param array $options XML generator options for objects and arrays
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 * @return object A reference to the appended child node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 function &append(&$child, $options = array()) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 if (empty($child)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 $return = false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 return $return;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 if (is_object($child)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 if ($this->compare($child)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 trigger_error(__('Cannot append a node to itself.', true));
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 $return = false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 return $return;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 } else if (is_array($child)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 $child = Set::map($child);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 if (is_array($child)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 if (!is_a(current($child), 'XmlNode')) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 foreach ($child as $i => $childNode) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 $child[$i] = $this->normalize($childNode, null, $options);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 foreach ($child as $childNode) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 $this->append($childNode, $options);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 return $child;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 $attributes = array();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 if (func_num_args() >= 2) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 $attributes = func_get_arg(1);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 $child =& $this->createNode($child, null, $attributes);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 $child = $this->normalize($child, null, $options);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 if (empty($child->namespace) && !empty($this->namespace)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 $child->namespace = $this->namespace;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 if (is_a($child, 'XmlNode')) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 $child->setParent($this);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 return $child;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 * Returns first child node, or null if empty.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 * @return object First XmlNode
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 function &first() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 if (isset($this->children[0])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 return $this->children[0];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 $return = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 return $return;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 * Returns last child node, or null if empty.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 * @return object Last XmlNode
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 function &last() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 if (count($this->children) > 0) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 return $this->children[count($this->children) - 1];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 $return = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 return $return;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
473
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 * Returns child node with given ID.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 * @param string $id Name of child node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 * @return object Child XmlNode
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 function &child($id) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 $null = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 if (is_int($id)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 if (isset($this->children[$id])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 return $this->children[$id];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 return null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 } elseif (is_string($id)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 for ($i = 0; $i < count($this->children); $i++) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 if ($this->children[$i]->name == $id) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 return $this->children[$i];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 return $null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 * Gets a list of childnodes with the given tag name.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 * @param string $name Tag name of child nodes
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 * @return array An array of XmlNodes with the given tag name
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 function children($name) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 $nodes = array();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 $count = count($this->children);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 for ($i = 0; $i < $count; $i++) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 if ($this->children[$i]->name == $name) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 $nodes[] =& $this->children[$i];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 return $nodes;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 * Gets a reference to the next child node in the list of this node's parent.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 * @return object A reference to the XmlNode object
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 function &nextSibling() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 $null = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 $count = count($this->__parent->children);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 for ($i = 0; $i < $count; $i++) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 if ($this->__parent->children[$i] == $this) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 if ($i >= $count - 1 || !isset($this->__parent->children[$i + 1])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 return $null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 return $this->__parent->children[$i + 1];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 return $null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 * Gets a reference to the previous child node in the list of this node's parent.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 * @return object A reference to the XmlNode object
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 function &previousSibling() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 $null = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 $count = count($this->__parent->children);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 for ($i = 0; $i < $count; $i++) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 if ($this->__parent->children[$i] == $this) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 if ($i == 0 || !isset($this->__parent->children[$i - 1])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 return $null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 return $this->__parent->children[$i - 1];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 return $null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 * Returns parent node.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 * @return object Parent XmlNode
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 function &parent() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 return $this->__parent;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
566 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
567
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
568 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 * Returns the XML document to which this node belongs
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 * @return object Parent XML object
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 function &document() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575 $document =& $this;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 while (true) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 if (get_class($document) == 'Xml' || $document == null) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 break;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 $document =& $document->parent();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 return $document;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 * Returns true if this structure has child nodes.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 * @return bool
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 function hasChildren() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 if (is_array($this->children) && !empty($this->children)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 return true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 * Returns this XML structure as a string.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 * @return string String representation of the XML structure.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 function toString($options = array(), $depth = 0) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 if (is_int($options)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 $depth = $options;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 $options = array();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 $defaults = array('cdata' => true, 'whitespace' => false, 'convertEntities' => false, 'showEmpty' => true, 'leaveOpen' => false);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 $options = array_merge($defaults, Xml::options(), $options);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 $tag = !(strpos($this->name, '#') === 0);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 $d = '';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
613
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 if ($tag) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 if ($options['whitespace']) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 $d .= str_repeat("\t", $depth);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
618
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 $d .= '<' . $this->name();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
620 if (!empty($this->namespaces) > 0) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 foreach ($this->namespaces as $key => $val) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
622 $val = str_replace('"', '\"', $val);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
623 $d .= ' xmlns:' . $key . '="' . $val . '"';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
626
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 $parent =& $this->parent();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 if ($parent->name === '#document' && !empty($parent->namespaces)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 foreach ($parent->namespaces as $key => $val) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 $val = str_replace('"', '\"', $val);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 $d .= ' xmlns:' . $key . '="' . $val . '"';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
632 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
634
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 if (is_array($this->attributes) && !empty($this->attributes)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 foreach ($this->attributes as $key => $val) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 if (is_bool($val) && $val === false) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 $val = 0;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 $d .= ' ' . $key . '="' . htmlspecialchars($val, ENT_QUOTES, Configure::read('App.encoding')) . '"';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
643 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 if (!$this->hasChildren() && empty($this->value) && $this->value !== 0 && $tag) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 if (!$options['leaveOpen']) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 $d .= ' />';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 if ($options['whitespace']) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
650 $d .= "\n";
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 } elseif ($tag || $this->hasChildren()) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 if ($tag) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 $d .= '>';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
655 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 if ($this->hasChildren()) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
657 if ($options['whitespace']) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 $d .= "\n";
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
659 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 $count = count($this->children);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 $cDepth = $depth + 1;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
662 for ($i = 0; $i < $count; $i++) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 $d .= $this->children[$i]->toString($options, $cDepth);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 if ($tag) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 if ($options['whitespace'] && $tag) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 $d .= str_repeat("\t", $depth);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 if (!$options['leaveOpen']) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 $d .= '</' . $this->name() . '>';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 if ($options['whitespace']) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
673 $d .= "\n";
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
674 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
675 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
677 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 return $d;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
680
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 * Return array representation of current object.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 * @param boolean $camelize true will camelize child nodes, false will not alter node names
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 * @return array Array representation
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
687 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688 function toArray($camelize = true) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 $out = $this->attributes;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
690
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 foreach ($this->children as $child) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
692 $key = $camelize ? Inflector::camelize($child->name) : $child->name;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
693
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
694 $leaf = false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 if (is_a($child, 'XmlTextNode')) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
696 $out['value'] = $child->value;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 continue;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 } elseif (isset($child->children[0]) && is_a($child->children[0], 'XmlTextNode')) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 $value = $child->children[0]->value;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 if ($child->attributes) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 $value = array_merge(array('value' => $value), $child->attributes);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 if (count($child->children) == 1) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 $leaf = true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 } elseif (count($child->children) === 0 && $child->value == '') {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 $value = $child->attributes;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
708 if (empty($value)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 $leaf = true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
712 $value = $child->toArray($camelize);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
713 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
715 if (isset($out[$key])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 if(!isset($out[$key][0]) || !is_array($out[$key]) || !is_int(key($out[$key]))) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
717 $out[$key] = array($out[$key]);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
718 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 $out[$key][] = $value;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 } elseif (isset($out[$child->name])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 $t = $out[$child->name];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 unset($out[$child->name]);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 $out[$key] = array($t);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 $out[$key][] = $value;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
725 } elseif ($leaf) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 $out[$child->name] = $value;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 $out[$key] = $value;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 return $out;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735 * Returns data from toString when this object is converted to a string.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 * @return string String representation of this structure.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 * @access private
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 function __toString() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 return $this->toString();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
743
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 * Debug method. Deletes the parent. Also deletes this node's children,
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
746 * if given the $recursive parameter.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
747 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
748 * @param boolean $recursive Recursively delete elements.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 * @access protected
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751 function _killParent($recursive = true) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
752 unset($this->__parent, $this->_log);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753 if ($recursive && $this->hasChildren()) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754 for ($i = 0; $i < count($this->children); $i++) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 $this->children[$i]->_killParent(true);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 * Main XML class.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
763 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 * Parses and stores XML data, representing the root of an XML document
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 * @package cake
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 * @subpackage cake.cake.libs
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 * @since CakePHP v .0.10.3.1400
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
769 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
770 class Xml extends XmlNode {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
771
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 * Resource handle to XML parser.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
774 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 * @var resource
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 * @access private
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
777 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
778 var $__parser;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
779
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
780 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 * File handle to XML indata file.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 * @var resource
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
784 * @access private
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786 var $__file;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
788 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789 * Raw XML string data (for loading purposes)
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791 * @var string
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 * @access private
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 var $__rawData = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
795
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
797 * XML document header
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
799 * @var string
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
800 * @access private
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
801 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
802 var $__header = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
803
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
804 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
805 * Default array keys/object properties to use as tag names when converting objects or array
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 * structures to XML. Set by passing $options['tags'] to this object's constructor.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808 * @var array
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
809 * @access private
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811 var $__tags = array();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
812
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
813 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814 * XML document version
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
815 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
816 * @var string
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 * @access private
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
819 var $version = '1.0';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
821 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 * XML document encoding
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
824 * @var string
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
825 * @access private
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
826 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
827 var $encoding = 'UTF-8';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
828
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
829 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
830 * Constructor. Sets up the XML parser with options, gives it this object as
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831 * its XML object, and sets some variables.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
832 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
833 * ### Options
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
834 * - 'root': The name of the root element, defaults to '#document'
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 * - 'version': The XML version, defaults to '1.0'
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836 * - 'encoding': Document encoding, defaults to 'UTF-8'
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
837 * - 'namespaces': An array of namespaces (as strings) used in this document
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838 * - 'format': Specifies the format this document converts to when parsed or
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
839 * rendered out as text, either 'attributes' or 'tags', defaults to 'attributes'
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 * - 'tags': An array specifying any tag-specific formatting options, indexed
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
841 * by tag name. See XmlNode::normalize().
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
842 * - 'slug': A boolean to indicate whether or not you want the string version of the XML document
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
843 * to have its tags run through Inflector::slug(). Defaults to true
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
845 * @param mixed $input The content with which this XML document should be initialized. Can be a
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
846 * string, array or object. If a string is specified, it may be a literal XML
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
847 * document, or a URL or file path to read from.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
848 * @param array $options Options to set up with, for valid options see above:
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849 * @see XmlNode::normalize()
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
850 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
851 function __construct($input = null, $options = array()) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
852 $defaults = array(
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
853 'root' => '#document', 'tags' => array(), 'namespaces' => array(),
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
854 'version' => '1.0', 'encoding' => 'UTF-8', 'format' => 'attributes',
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
855 'slug' => true
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
856 );
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
857 $options = array_merge($defaults, Xml::options(), $options);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
858
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
859 foreach (array('version', 'encoding', 'namespaces') as $key) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
860 $this->{$key} = $options[$key];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
861 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
862 $this->__tags = $options['tags'];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
863 parent::__construct('#document');
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
864
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865 if ($options['root'] !== '#document') {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
866 $Root =& $this->createNode($options['root']);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
867 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
868 $Root =& $this;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
869 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
870
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
871 if (!empty($input)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
872 if (is_string($input)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
873 $Root->load($input);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
874 } elseif (is_array($input) || is_object($input)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
875 $Root->append($input, $options);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
876 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
878 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
879
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
880 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
881 * Initialize XML object from a given XML string. Returns false on error.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
882 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
883 * @param string $input XML string, a path to a file, or an HTTP resource to load
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
884 * @return boolean Success
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
885 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
886 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
887 function load($input) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
888 if (!is_string($input)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
889 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
890 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
891 $this->__rawData = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
892 $this->__header = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
893
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
894 if (strstr($input, "<")) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
895 $this->__rawData = $input;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
896 } elseif (strpos($input, 'http://') === 0 || strpos($input, 'https://') === 0) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
897 App::import('Core', 'HttpSocket');
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
898 $socket = new HttpSocket();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
899 $this->__rawData = $socket->get($input);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
900 } elseif (file_exists($input)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
901 $this->__rawData = file_get_contents($input);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
902 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
903 trigger_error(__('XML cannot be read', true));
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
904 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
905 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
906 return $this->parse();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
907 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
908
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
909 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
910 * Parses and creates XML nodes from the __rawData property.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 * @return boolean Success
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
913 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
914 * @see Xml::load()
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
915 * @todo figure out how to link attributes and namespaces
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
916 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
917 function parse() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
918 $this->__initParser();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 $this->__rawData = trim($this->__rawData);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
920 $this->__header = trim(str_replace(
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
921 array('<' . '?', '?' . '>'),
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
922 array('', ''),
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
923 substr($this->__rawData, 0, strpos($this->__rawData, '?' . '>'))
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
924 ));
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
925
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
926 xml_parse_into_struct($this->__parser, $this->__rawData, $vals);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
927 $xml =& $this;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
928 $count = count($vals);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
929
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
930 for ($i = 0; $i < $count; $i++) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
931 $data = $vals[$i];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
932 $data += array('tag' => null, 'value' => null, 'attributes' => array());
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
933 switch ($data['type']) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
934 case "open" :
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
935 $xml =& $xml->createElement($data['tag'], $data['value'], $data['attributes']);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
936 break;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
937 case "close" :
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 $xml =& $xml->parent();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
939 break;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
940 case "complete" :
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
941 $xml->createElement($data['tag'], $data['value'], $data['attributes']);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
942 break;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
943 case 'cdata':
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
944 $xml->createTextNode($data['value']);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
945 break;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
946 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
947 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
948 xml_parser_free($this->__parser);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
949 $this->__parser = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
950 return true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
951 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
952
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
953 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
954 * Initializes the XML parser resource
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
955 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
956 * @return void
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
957 * @access private
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
958 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
959 function __initParser() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
960 if (empty($this->__parser)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
961 $this->__parser = xml_parser_create();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
962 xml_set_object($this->__parser, $this);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
963 xml_parser_set_option($this->__parser, XML_OPTION_CASE_FOLDING, 0);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
964 xml_parser_set_option($this->__parser, XML_OPTION_SKIP_WHITE, 1);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
965 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
966 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
967
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
968 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
969 * Returns a string representation of the XML object
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
970 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
971 * @param mixed $options If boolean: whether to include the XML header with the document
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
972 * (defaults to true); if an array, overrides the default XML generation options
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
973 * @return string XML data
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
975 * @deprecated
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
976 * @see Xml::toString()
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
977 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
978 function compose($options = array()) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
979 return $this->toString($options);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
980 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
981
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
982 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
983 * If debug mode is on, this method echoes an error message.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
984 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
985 * @param string $msg Error message
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
986 * @param integer $code Error code
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
987 * @param integer $line Line in file
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
988 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
989 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
990 function error($msg, $code = 0, $line = 0) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
991 if (Configure::read('debug')) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
992 echo $msg . " " . $code . " " . $line;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
993 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
994 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
995
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
996 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997 * Returns a string with a textual description of the error code, or FALSE if no description was found.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
998 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
999 * @param integer $code Error code
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000 * @return string Error message
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1001 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1002 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1003 function getError($code) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004 $r = @xml_error_string($code);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1005 return $r;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1006 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1007
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1008 // Overridden functions from superclass
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1009
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1010 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1011 * Get next element. NOT implemented.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1012 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1013 * @return object
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1014 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1015 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1016 function &next() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1017 $return = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1018 return $return;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1019 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1020
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1021 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1022 * Get previous element. NOT implemented.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1023 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024 * @return object
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1025 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1026 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027 function &previous() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1028 $return = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1029 return $return;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1030 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1031
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1032 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1033 * Get parent element. NOT implemented.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1034 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1035 * @return object
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1036 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1038 function &parent() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1039 $return = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040 return $return;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1041 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1042
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1043 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1044 * Adds a namespace to the current document
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1045 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1046 * @param string $prefix The namespace prefix
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1047 * @param string $url The namespace DTD URL
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1048 * @return void
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1049 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1050 function addNamespace($prefix, $url) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 if ($count = count($this->children)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052 for ($i = 0; $i < $count; $i++) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 $this->children[$i]->addNamespace($prefix, $url);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1055 return true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1057 return parent::addNamespace($prefix, $url);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1058 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1059
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1060 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1061 * Removes a namespace to the current document
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1062 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1063 * @param string $prefix The namespace prefix
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1064 * @return void
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1065 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1066 function removeNamespace($prefix) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1067 if ($count = count($this->children)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1068 for ($i = 0; $i < $count; $i++) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1069 $this->children[$i]->removeNamespace($prefix);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1070 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1071 return true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1072 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1073 return parent::removeNamespace($prefix);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1074 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1075
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1076 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1077 * Return string representation of current object.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1078 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1079 * @return string String representation
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1080 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1081 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1082 function toString($options = array()) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1083 if (is_bool($options)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1084 $options = array('header' => $options);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1085 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1086
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1087 $defaults = array('header' => false, 'encoding' => $this->encoding);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1088 $options = array_merge($defaults, Xml::options(), $options);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1089 $data = parent::toString($options, 0);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1090
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1091 if ($options['header']) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1092 if (!empty($this->__header)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1093 return $this->header($this->__header) . "\n" . $data;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1094 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1095 return $this->header() . "\n" . $data;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1096 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1097
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1098 return $data;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1099 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1100
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1101 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1102 * Return a header used on the first line of the xml file
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1103 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1104 * @param mixed $attrib attributes of the header element
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1105 * @return string formated header
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1106 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1107 function header($attrib = array()) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1108 $header = 'xml';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1109 if (is_string($attrib)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1110 $header = $attrib;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1111 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1112
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1113 $attrib = array_merge(array('version' => $this->version, 'encoding' => $this->encoding), $attrib);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1114 foreach ($attrib as $key=>$val) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1115 $header .= ' ' . $key . '="' . $val . '"';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1116 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1117 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1118 return '<' . '?' . $header . ' ?' . '>';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1119 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1120
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1121 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1122 * Destructor, used to free resources.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1123 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1124 * @access private
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1125 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1126 function __destruct() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1127 $this->_killParent(true);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1128 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1129
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1130 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1131 * Adds a namespace to any XML documents generated or parsed
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1132 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1133 * @param string $name The namespace name
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1134 * @param string $url The namespace URI; can be empty if in the default namespace map
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1135 * @return boolean False if no URL is specified, and the namespace does not exist
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1136 * default namespace map, otherwise true
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1137 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1138 * @static
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1139 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1140 function addGlobalNs($name, $url = null) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1141 $_this =& XmlManager::getInstance();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1142 if ($ns = Xml::resolveNamespace($name, $url)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1143 $_this->namespaces = array_merge($_this->namespaces, $ns);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1144 return $ns;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1145 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1146 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1147 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1148
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1149 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1150 * Resolves current namespace
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1151 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1152 * @param string $name
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1153 * @param string $url
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1154 * @return array
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1155 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1156 function resolveNamespace($name, $url) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1157 $_this =& XmlManager::getInstance();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158 if ($url == null && isset($_this->defaultNamespaceMap[$name])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159 $url = $_this->defaultNamespaceMap[$name];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160 } elseif ($url == null) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1161 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1162 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164 if (!strpos($url, '://') && isset($_this->defaultNamespaceMap[$name])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1165 $_url = $_this->defaultNamespaceMap[$name];
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166 $name = $url;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167 $url = $_url;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1169 return array($name => $url);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1171
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173 * Alias to Xml::addNs
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1174 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1175 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1176 * @static
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1177 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1178 function addGlobalNamespace($name, $url = null) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1179 return Xml::addGlobalNs($name, $url);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1180 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1181
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1182 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1183 * Removes a namespace added in addNs()
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1185 * @param string $name The namespace name or URI
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1186 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1187 * @static
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1188 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1189 function removeGlobalNs($name) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1190 $_this =& XmlManager::getInstance();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1191 if (isset($_this->namespaces[$name])) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1192 unset($_this->namespaces[$name]);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1193 unset($this->namespaces[$name]);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1194 return true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1195 } elseif (in_array($name, $_this->namespaces)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1196 $keys = array_keys($_this->namespaces);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1197 $count = count($keys);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1198 for ($i = 0; $i < $count; $i++) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1199 if ($_this->namespaces[$keys[$i]] == $name) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1200 unset($_this->namespaces[$keys[$i]]);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1201 unset($this->namespaces[$keys[$i]]);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1202 return true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1203 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1204 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1205 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1206 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1207 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1208
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1209 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1210 * Alias to Xml::removeNs
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1211 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1212 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1213 * @static
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1214 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1215 function removeGlobalNamespace($name) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1216 return Xml::removeGlobalNs($name);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1217 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1218
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1219 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1220 * Sets/gets global XML options
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1221 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1222 * @param array $options
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1223 * @return array
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1224 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1225 * @static
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1226 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1227 function options($options = array()) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1228 $_this =& XmlManager::getInstance();
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1229 $_this->options = array_merge($_this->options, $options);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1230 return $_this->options;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1231 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1232 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1233
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1234 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1235 * The XML Element
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1236 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1237 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1238 class XmlElement extends XmlNode {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1239
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1240 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1241 * Construct an Xml element
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1242 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1243 * @param string $name name of the node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1244 * @param string $value value of the node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1245 * @param array $attributes
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1246 * @param string $namespace
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1247 * @return string A copy of $data in XML format
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1248 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1249 function __construct($name = null, $value = null, $attributes = array(), $namespace = false) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1250 parent::__construct($name, $value, $namespace);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1251 $this->addAttribute($attributes);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1252 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1253
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1254 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1255 * Get all the attributes for this element
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1256 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1257 * @return array
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1258 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1259 function attributes() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1260 return $this->attributes;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1261 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1262
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1263 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1264 * Add attributes to this element
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1265 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1266 * @param string $name name of the node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1267 * @param string $value value of the node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1268 * @return boolean
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1269 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1270 function addAttribute($name, $val = null) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1271 if (is_object($name)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1272 $name = get_object_vars($name);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1273 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1274 if (is_array($name)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1275 foreach ($name as $key => $val) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1276 $this->addAttribute($key, $val);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1277 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1278 return true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1279 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1280 if (is_numeric($name)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1281 $name = $val;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1282 $val = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1283 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1284 if (!empty($name)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1285 if (strpos($name, 'xmlns') === 0) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1286 if ($name == 'xmlns') {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1287 $this->namespace = $val;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1288 } else {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1289 list($pre, $prefix) = explode(':', $name);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1290 $this->addNamespace($prefix, $val);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1291 return true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1292 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1293 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1294 $this->attributes[$name] = $val;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1295 return true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1296 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1297 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1298 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1299
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1300 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1301 * Remove attributes to this element
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1302 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1303 * @param string $name name of the node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1304 * @return boolean
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1305 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1306 function removeAttribute($attr) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1307 if (array_key_exists($attr, $this->attributes)) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1308 unset($this->attributes[$attr]);
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1309 return true;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1310 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1311 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1312 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1313 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1314
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1315 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1316 * XML text or CDATA node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1317 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1318 * Stores XML text data according to the encoding of the parent document
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1319 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1320 * @package cake
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1321 * @subpackage cake.cake.libs
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1322 * @since CakePHP v .1.2.6000
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1323 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1324 class XmlTextNode extends XmlNode {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1325
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1326 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1327 * Harcoded XML node name, represents this object as a text node
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1328 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1329 * @var string
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1330 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1331 var $name = '#text';
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1332
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1333 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1334 * The text/data value which this node contains
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1335 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1336 * @var string
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1337 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1338 var $value = null;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1339
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1340 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1341 * Construct text node with the given parent object and data
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1342 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1343 * @param object $parent Parent XmlNode/XmlElement object
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1344 * @param mixed $value Node value
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1345 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1346 function __construct($value = null) {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1347 $this->value = $value;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1348 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1349
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1350 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1351 * Looks for child nodes in this element
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1352 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1353 * @return boolean False - not supported
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1354 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1355 function hasChildren() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1356 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1357 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1358
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1359 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1360 * Append an XML node: XmlTextNode does not support this operation
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1361 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1362 * @return boolean False - not supported
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1363 * @todo make convertEntities work without mb support, convert entities to number entities
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1364 */
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1365 function append() {
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1366 return false;
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1367 }
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1368
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1369 /**
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1370 * Return string representation of current text node object.
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1371 *
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1372 * @return string String representation
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1373 * @access public
261e66bd5a0c hg init
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1374 */