10 function DomXml($xml_data) {
11 if (@is_file($xml_data)) {
12 if (! $this->dom = domxml_open_file($xml_data)) {
13 //echo "Error while parsing the document.\n";
18 if (! $this->dom = domxml_open_mem($xml_data)) {
19 echo "<!-- Error while parsing the document. -->\n";
32 if (empty($this->dom)) {
35 $root = new DomXmlNode($this->dom->document_element());
36 $nodes = new DomXmlNodes($root);
45 function getNodes($tag_name) {
46 $root = DomXml::getRoot();
48 return $root->getNodes("$tag_name");
58 function getNode($tag_name) {
59 $nodes = DomXml::getNodes($tag_name);
61 return $nodes->next();
70 function getNodeContent($tag_name) {
71 $node = DomXml::getNode($tag_name);
73 return $node->getContent();
78 function get($tag_name) {
79 return DomXml::getNodeContent($tag_name);
88 var $current_node = -1;
90 function DomXmlNodes($nodes) {
91 if (is_array($nodes)) {
92 $this->nodes = $nodes;
94 $this->nodes = array($nodes);
102 if ($this->current_node + 1 >= count($this->nodes)) {
105 $this->current_node += 1;
106 return $this->nodes[$this->current_node];
113 $this->current_node = -1;
119 function getNodes($node_name) {
120 $node_names = explode("/",$node_name);
121 $last_node_name = array_pop($node_names);
123 $node = $this->nodes[0];
124 print_r($this->nodes[1]);
125 while ($node_name = array_shift($node_names)) {
126 $found_node = $node->findNode($node_name);
128 return new DomXmlNodes(array());
130 $node = new DomXmlNode($found_node);
132 $found_node = $node->findNodes($last_node_name);
134 return new DomXmlNodes($found_node);
136 return new DomXmlNodes(array());
143 function getNode($node_name) {
144 $nodes = DomXmlNodes::getNodes($node_name);
146 return $nodes->next();
154 function getNodeContent($tag_name) {
155 $node = DomXmlNodes::getNode();
157 return $node->getContent();
162 function get($tag_name) {
163 return DomXml::getNodeContent($tag_name);
167 return DomXmlNodes::getNumRows();
170 function getNumRows() {
171 return @count($this->nodes);
181 var $output_encoding = '';
183 function DomXmlNode($node,$output_encoding = 'windows-1250') {
185 if ($output_encoding) {
186 $this->output_encoding = $output_encoding;
193 function getContent() {
195 if ($this->node && $this->node->has_child_nodes()) {
196 $node = array_shift($this->node->child_nodes());
201 $content = $node->get_content();
202 $content = str_replace("#parse_nl#"," ",$content);
203 $content = DomXmlNode::unhtmlspecialchars($content);
209 * content of subnode specified by node name
211 function getNodeContent($node_name) {
212 $node_names = explode("/",$node_name);
213 $last_node_name = array_pop($node_names);
216 while ($node_name = array_shift($node_names)) {
217 $found_node = $node->findNode($node_name);
221 $node = new DomXmlNode($found_node);
224 if ($node = $node->findNode($last_node_name)) {
225 $node = new DomXmlNode($node);
226 return $node->getContent();
231 function get($node_name='') {
233 return DomXmlNode::getNodeContent($node_name);
235 return DomXmlNode::getContent();
242 function findNode($node_name) {
245 if (! ($node || $node->has_child_node()) ) {
250 $child = $node->first_child();
253 if ($child->node_type() == XML_ELEMENT_NODE && $child->tagname() == $node_name) {
256 $child = $child->next_sibling();
265 function findNodes($node_name) {
270 if (! ($node || $node->has_child_node()) ) {
274 $child = $node->first_child();
277 if ($child->node_type() == XML_ELEMENT_NODE && $child->tagname() == $node_name) {
278 $nodes[] = new DomXmlNode($child);
280 $child = $child->next_sibling();
286 function unhtmlspecialchars($str) {
287 $html_special_chars_table = array(
297 $html_special_chars_table = array_flip($html_special_chars_table);
299 return strtr($str,$html_special_chars_table);