comparison class.template.php @ 8:0b796d56c767

Suppression du pre-supposé selon lequel l'espace de template est prefixé t.
author Franck Deroche <webmaster@defr.org>
date Sun, 21 Oct 2007 14:18:09 +0200
parents 61dee7e34a9d
children d06e9d5ff344
comparison
equal deleted inserted replaced
7:61dee7e34a9d 8:0b796d56c767
8 function __construct($fileName, $shouldValidate = false) { 8 function __construct($fileName, $shouldValidate = false) {
9 $this->xmlDocument = new DOMDocument(); 9 $this->xmlDocument = new DOMDocument();
10 $this->xmlDocument->validateOnParse = $shouldValidate; 10 $this->xmlDocument->validateOnParse = $shouldValidate;
11 $this->xmlDocument->loadXML(file_get_contents($fileName)); 11 $this->xmlDocument->loadXML(file_get_contents($fileName));
12 $this->xmlXPath = new DOMXPath($this->xmlDocument); 12 $this->xmlXPath = new DOMXPath($this->xmlDocument);
13 $this->xmlXPath->registerNamespace('_t', Template::NS);
13 } 14 }
14 15
15 function apply($selector, $obj, DOMElement $root = null) { 16 function apply($selector, $obj, DOMElement $root = null) {
16 if(!($root instanceof DOMElement)) 17 if(!($root instanceof DOMElement))
17 $root = $this->xmlDocument->documentElement; 18 $root = $this->xmlDocument->documentElement;
77 if($pos !== false) { 78 if($pos !== false) {
78 $obj['attribute'] = substr($selector,$pos +1); 79 $obj['attribute'] = substr($selector,$pos +1);
79 $selector = substr($selector, 0, $pos); 80 $selector = substr($selector, 0, $pos);
80 } 81 }
81 if($selector[0] == '#') { 82 if($selector[0] == '#') {
82 $obj['xpath'] = "//*[@t:id='" . substr($selector, 1) . "']"; 83 $obj['xpath'] = "//*[@_t:id='" . substr($selector, 1) . "']";
83 $obj['nodes'] = $this->xmlXPath->query($obj['xpath'], $root); 84 $obj['nodes'] = $this->xmlXPath->query($obj['xpath'], $root);
84 } 85 }
85 else { 86 else {
86 $obj['nodeName'] = $selector; 87 $obj['nodeName'] = $selector;
87 $obj['nodes'] = $root->getElementsByTagName($selector); 88 $obj['nodes'] = $root->getElementsByTagName($selector);
138 $node->appendChild($content); 139 $node->appendChild($content);
139 } 140 }
140 141
141 function clean() { 142 function clean() {
142 // Suppression des noeuds à cloner 143 // Suppression des noeuds à cloner
143 $nodes = $this->xmlXPath->query("//*[@t:toClone]|//t:*"); 144 $nodes = $this->xmlXPath->query("//*[@_t:toClone]|//_t:*");
144 foreach($nodes as $node) { 145 foreach($nodes as $node) {
145 if($node->parentNode) { 146 if($node->parentNode) {
146 $node->parentNode->removeChild($node); 147 $node->parentNode->removeChild($node);
147 } 148 }
148 } 149 }