docker dev update
[openemr.git] / library / classes / XmlWriterOemr.class.php
blob636451fb7c7919f8579c0171f27a80aa69d7e9e8
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
13 var $xml;
14 var $indent;
15 var $stack = array();
16 function __construct($indent = ' ')
18 $this->indent = $indent;
19 $this->xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
21 function _indent()
23 for ($i = 0, $j = count($this->stack); $i < $j; $i++) {
24 $this->xml .= $this->indent;
27 function push($element, $attributes = array())
29 $this->_indent();
30 $this->xml .= '<'.$element;
31 foreach ($attributes as $key => $value) {
32 $this->xml .= ' '.htmlspecialchars($key).'="'.htmlspecialchars($value).'"';
35 $this->xml .= ">\n";
36 $this->stack[] = htmlspecialchars($element);
38 function element($element, $content, $attributes = array())
40 $this->_indent();
41 $this->xml .= '<'.$element;
42 foreach ($attributes as $key => $value) {
43 $this->xml .= ' '.htmlspecialchars($key).'="'.htmlspecialchars($value).'"';
46 $this->xml .= '>'.htmlspecialchars($content).'</'.htmlspecialchars($element).'>'."\n";
48 function emptyelement($element, $attributes = array())
50 $this->_indent();
51 $this->xml .= '<'.htmlspecialchars($element);
52 foreach ($attributes as $key => $value) {
53 $this->xml .= ' '.htmlspecialchars($key).'="'.htmlspecialchars($value).'"';
56 $this->xml .= " />\n";
58 function pop()
60 $element = array_pop($this->stack);
61 $this->_indent();
62 $this->xml .= "</".htmlspecialchars($element).">"."\n";
64 function getXml()
66 return $this->xml;