Space to separate "&&" so that all "&$var" can be made into "$var" later
[openemr.git] / library / classes / XmlWriterOemr.class.php
bloba46248e8d8fe1e8df3652473abfbc1b26489e012
1 <?php
2 // Copyright (C) 2011 Ensoftek
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This program is the base class to implement XML writer.
11 class XmlWriterOemr {
12 var $xml;
13 var $indent;
14 var $stack = array();
15 function XmlWriterOemr($indent = ' ') {
16 $this->indent = $indent;
17 $this->xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
19 function _indent() {
20 for ($i = 0, $j = count($this->stack); $i < $j; $i++) {
21 $this->xml .= $this->indent;
24 function push($element, $attributes = array()) {
25 $this->_indent();
26 $this->xml .= '<'.$element;
27 foreach ($attributes as $key => $value) {
28 $this->xml .= ' '.htmlspecialchars($key).'="'.htmlspecialchars($value).'"';
30 $this->xml .= ">\n";
31 $this->stack[] = htmlspecialchars($element);
33 function element($element, $content, $attributes = array()) {
34 $this->_indent();
35 $this->xml .= '<'.$element;
36 foreach ($attributes as $key => $value) {
37 $this->xml .= ' '.htmlspecialchars($key).'="'.htmlspecialchars($value).'"';
39 $this->xml .= '>'.htmlspecialchars($content).'</'.htmlspecialchars($element).'>'."\n";
41 function emptyelement($element, $attributes = array()) {
42 $this->_indent();
43 $this->xml .= '<'.htmlspecialchars($element);
44 foreach ($attributes as $key => $value) {
45 $this->xml .= ' '.htmlspecialchars($key).'="'.htmlspecialchars($value).'"';
47 $this->xml .= " />\n";
49 function pop() {
50 $element = array_pop($this->stack);
51 $this->_indent();
52 $this->xml .= "</".htmlspecialchars($element).">"."\n";
54 function getXml() {
55 return $this->xml;