Changeset 17
- Timestamp:
- 08/27/06 23:26:39 (2 years ago)
- Files:
-
- trunk/XJConf/DefinitionParser.php (modified) (1 diff)
- trunk/XJConf/XmlParser.php (modified) (12 diffs)
- trunk/examples/TestXInclude.php (added)
- trunk/examples/xml/test-xinclude-included.xml (added)
- trunk/examples/xml/test-xinclude.xml (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/XJConf/DefinitionParser.php
r14 r17 218 218 } 219 219 220 // if ($defHandler->needsEnd() == true) { 221 array_push($this->defHandlerStack, $defHandler); 222 // } 220 array_push($this->defHandlerStack, $defHandler); 223 221 } 224 222 trunk/XJConf/XmlParser.php
r9 r17 39 39 * a listof defined namespaces 40 40 * 41 * @var NamespaceDefinitions 41 * @var NamespaceDefinitions 42 42 */ 43 43 private $tagDefs; … … 78 78 */ 79 79 private $nodeTypes = array(); 80 80 81 81 /** 82 82 * constructor 83 * 83 * 84 84 * Sets the node types depending on your PHP version using the constants 85 85 * defined by the XMLReader PHP extension. … … 99 99 } 100 100 } 101 101 102 102 /** 103 103 * set the list of namespace defintions … … 109 109 $this->tagDefs = $tagDefs; 110 110 } 111 111 112 112 /** 113 113 * add some more namespace definitions … … 124 124 $this->tagDefs->appendNamespaceDefinitions($tagDefs); 125 125 } 126 126 127 127 /** 128 128 * add an extension that handles all tags in given namespace … … 131 131 * @param Extension $ext use this extension to handle all tags in given namespace 132 132 */ 133 public function addExtension($namespace, Extension $ext) 134 { 133 public function addExtension(Extension $ext, $namespace = null) 134 { 135 if ($namespace == null) { 136 $namespace = $ext->getNamespace(); 137 } 135 138 $this->extensions[$namespace] = $ext; 136 139 } 137 140 138 141 /** 139 142 * parses a given file and creates the data structure described in this file … … 143 146 public function parse($filename) 144 147 { 145 $ this->initParser();148 $reader = $this->initParser(); 146 149 array_push($this->openFiles, $filename); 147 $ this->reader->open($filename);148 while ($ this->reader->read()) {149 switch ($ this->reader->nodeType) {150 $reader->open($filename); 151 while ($reader->read()) { 152 switch ($reader->nodeType) { 150 153 case $this->nodeTypes['startTag']: 151 $nameSpaceURI = $this->reader->namespaceURI; 152 $elementName = $this->reader->localName; 154 $empty = $reader->isEmptyElement; 155 $nameSpaceURI = $reader->namespaceURI; 156 $elementName = $reader->localName; 153 157 $attributes = array(); 154 if (TRUE == $ this->reader->hasAttributes) {158 if (TRUE == $reader->hasAttributes) { 155 159 // go to first attribute 156 $attribute = $ this->reader->moveToFirstAttribute();160 $attribute = $reader->moveToFirstAttribute(); 157 161 // save data of all attributes 158 162 while (TRUE == $attribute) { 159 $attributes[$ this->reader->localName] = $this->reader->value;160 $attribute = $ this->reader->moveToNextAttribute();163 $attributes[$reader->localName] = $reader->value; 164 $attribute = $reader->moveToNextAttribute(); 161 165 } 162 166 } 163 167 164 168 $this->startElement($nameSpaceURI, $elementName, $attributes); 169 if (true === $empty) { 170 $this->endElement($nameSpaceURI, $elementName); 171 } 165 172 break; 166 173 167 174 case $this->nodeTypes['text']: 168 $this->characters($ this->reader->value);175 $this->characters($reader->value); 169 176 break; 170 177 171 178 case $this->nodeTypes['endTag']: 172 $this->endElement($ this->reader->namespaceURI, $this->reader->localName);179 $this->endElement($reader->namespaceURI, $reader->localName); 173 180 break; 174 181 } 175 182 } 176 183 177 $ this->reader->close($filename);184 $reader->close($filename); 178 185 array_pop($this->openFiles); 179 186 180 187 } 181 188 182 189 /** 183 190 * returns the data structure associated with this name … … 190 197 return $this->config[$name]; 191 198 } 192 199 193 200 /** 194 201 * returns the name of the file that is currently parsed … … 200 207 return end($this->openFiles); 201 208 } 202 209 203 210 /** 204 211 * initializes the parser … … 206 213 private function initParser() 207 214 { 208 if (null == $this->reader) { 209 $this->reader = new XMLReader(); 210 } 215 $reader = new XMLReader(); 216 return $reader; 211 217 } 212 218 … … 290 296 // get the last tag from the stack 291 297 $tag = array_pop($this->tagStack); 292 298 293 299 // This tag needs to be handled by an extension 294 300 if (isset($this->extensions[$namespaceURI]) == true) { … … 323 329 * Fetches the current tag from the stack and 324 330 * appends the data. 325 * 331 * 326 332 * @param string $buf 327 333 */
