Merge pull request #7532 from sjpadgett/ccda
[openemr.git] / library / classes / XmlWriterOemr.class.php
blob52b45aa7333b312d401e6191dd333a5bc3221fd9
1 <?php
3 // Copyright (C) 2011 Ensoftek
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is the base class to implement XML writer.
12 class XmlWriterOemr
14 var $xml;
15 var $indent;
16 var $stack = array();
17 function __construct($indent = ' ')
19 $this->indent = $indent;
20 $this->xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
22 function _indent()
24 for ($i = 0, $j = count($this->stack); $i < $j; $i++) {
25 $this->xml .= $this->indent;
28 function push($element, $attributes = array())
30 $this->_indent();
31 $this->xml .= '<' . $element;
32 foreach ($attributes as $key => $value) {
33 $this->xml .= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
36 $this->xml .= ">\n";
37 $this->stack[] = htmlspecialchars($element);
39 function element($element, $content, $attributes = array())
41 $this->_indent();
42 $this->xml .= '<' . $element;
43 foreach ($attributes as $key => $value) {
44 $this->xml .= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
47 $this->xml .= '>' . htmlspecialchars($content) . '</' . htmlspecialchars($element) . '>' . "\n";
49 function emptyelement($element, $attributes = array())
51 $this->_indent();
52 $this->xml .= '<' . htmlspecialchars($element);
53 foreach ($attributes as $key => $value) {
54 $this->xml .= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
57 $this->xml .= " />\n";
59 function pop()
61 $element = array_pop($this->stack);
62 $this->_indent();
63 $this->xml .= "</" . htmlspecialchars($element) . ">" . "\n";
65 function getXml()
67 return $this->xml;