Public Member Functions | Data Fields

ilXmlWriter Class Reference

XML writer class. More...

Inheritance diagram for ilXmlWriter:

Public Member Functions

 ilXmlWriter ($version="1.0", $outEnc="utf-8", $inEnc="utf-8")
 constructor
 _ilXmlWriter ()
 destructor public
 xmlSetDtdDef ($dtdDef)
 Sets dtd definition.
 xmlSetStSheet ($stSheet)
 Sets stylesheet.
 xmlSetGenCmt ($genCmt)
 Sets generated comment.
 _xmlEscapeData ($data)
 Escapes reserved characters.
 xmlEncodeData ($data)
 Encodes text from input encoding into output encoding.
 xmlFormatData ($data)
 Indents text for better reading.
 xmlFormatElement ($array)
 Callback function for xmlFormatData; do not invoke directly.
 xmlHeader ()
 Writes xml header public.
 xmlStartTag ($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
 Writes a starttag.
 xmlEndTag ($tag)
 Writes an endtag.
 xmlComment ($comment)
 Writes a comment.
 xmlData ($data, $encode=TRUE, $escape=TRUE)
 Writes data.
 xmlElement ($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
 Writes a basic element (no children, just textual content).
 xmlDumpFile ($file, $format=TRUE)
 Dumps xml document from memory into a file.
 xmlDumpMem ($format=TRUE)
 Returns xml document from memory.
 appendXML ($a_str)
 append xml string to document
 xmlClear ()
 clears xmlStr public

Data Fields

 $xmlStr
 $version
 $outEnc
 $inEnc
 $dtdDef = ""
 $stSheet = ""
 $genCmt = "Generated by ILIAS XmlWriter"

Detailed Description

XML writer class.

Class to simplify manual writing of xml documents. It only supports writing xml sequentially, because the xml document is saved in a string with no additional structure information. The author is responsible for well-formedness and validity of the xml document.

Author:
Matthias Rulinski <matthias.rulinski@mi.uni-koeln.de>
Version:
Id:
class.ilXmlWriter.php 11749 2006-08-02 11:10:33Z smeyer

Definition at line 37 of file class.ilXmlWriter.php.


Member Function Documentation

ilXmlWriter::_ilXmlWriter (  ) 

destructor public

Definition at line 110 of file class.ilXmlWriter.php.

        {
                // terminate xml string
                unset($this->xmlStr);
        }

ilXmlWriter::_xmlEscapeData ( data  ) 

Escapes reserved characters.

Parameters:
string input text
Returns:
string escaped text static

Definition at line 152 of file class.ilXmlWriter.php.

References $data.

Referenced by ilLPFilterGUI::getFO(), ilLPItemListGUI::renderObjectListFO(), ilLPItemListGUI::renderSimpleProgressFO(), xmlData(), and xmlStartTag().

        {
                $position = 0;
                $length = strlen($data);
                $escapedData = "";
                
                for(; $position < $length;)
                {
                        $character = substr($data, $position, 1);
                        $code = Ord($character);
                        
                        switch($code)
                        {
                                case 34:
                                        $character = "&quot;";
                                        break;
                                
                                case 38:
                                        $character = "&amp;";
                                        break;
                                
                                case 39:
                                        $character = "&apos;";
                                        break;
                                
                                case 60:
                                        $character = "&lt;";
                                        break;
                                
                                case 62:
                                        $character = "&gt;";
                                        break;
                                
                                default:
                                        if ($code < 32)
                                        {
                                                $character = ("&#".strval($code).";");
                                        }
                                        break;
                        }
                        
                        $escapedData .= $character;
                        $position ++;
                }
                return $escapedData;
        }

Here is the caller graph for this function:

ilXmlWriter::appendXML ( a_str  ) 

append xml string to document

Definition at line 524 of file class.ilXmlWriter.php.

Referenced by ilCourseXMLWriter::__buildMetaData().

        {
                $this->xmlStr .= $a_str;
        }

Here is the caller graph for this function:

ilXmlWriter::ilXmlWriter ( version = "1.0",
outEnc = "utf-8",
inEnc = "utf-8" 
)

constructor

Parameters:
string xml version
string output encoding
string input encoding public

Definition at line 95 of file class.ilXmlWriter.php.

References $inEnc, $outEnc, and $version.

Referenced by ilCourseXMLWriter::ilCourseXMLWriter(), ilGroupXMLWriter::ilGroupXMLWriter(), ilMD2XML::ilMD2XML(), ilnetucateXMLAPI::ilnetucateXMLAPI(), ilObjectXMLWriter::ilObjectXMLWriter(), ilSoapRoleObjectXMLWriter::ilSoapRoleObjectXMLWriter(), ilSoapStructureObjectXMLWriter::ilSoapStructureObjectXMLWriter(), ilSoapUserObjectXMLWriter::ilSoapUserObjectXMLWriter(), and ilXMLResultSetWriter::ilXMLResultSetWriter().

        {
                // initialize xml string
                $this->xmlStr = "";
                
                // set properties
                $this->version = $version;
                $this->outEnc = $outEnc;
                $this->inEnc = $inEnc;
        }

Here is the caller graph for this function:

ilXmlWriter::xmlClear (  ) 
ilXmlWriter::xmlComment ( comment  ) 

Writes a comment.

Parameters:
string comment public

Definition at line 405 of file class.ilXmlWriter.php.

Referenced by xmlHeader().

        {
                $this->xmlStr .= "<!--".$comment."-->";
        }

Here is the caller graph for this function:

ilXmlWriter::xmlData ( data,
encode = TRUE,
escape = TRUE 
)

Writes data.

Parameters:
string data
string ecode data (TRUE) or not (FALSE)
string escape data (TRUE) or not (FALSE) public

Definition at line 417 of file class.ilXmlWriter.php.

References $data, _xmlEscapeData(), and xmlEncodeData().

Referenced by xmlElement().

        {
                // encode
                if ($encode)
                {
                    $data = $this->xmlEncodeData($data);
                }
                
                // escape
                if ($escape)
                {
                        $data = ilXmlWriter::_xmlEscapeData($data);
            }
                
                $this->xmlStr .= $data;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilXmlWriter::xmlDumpFile ( file,
format = TRUE 
)

Dumps xml document from memory into a file.

Parameters:
string file name (full path)
boolean indent text (TRUE) or not (FALSE) public

Definition at line 471 of file class.ilXmlWriter.php.

References $file, $xmlStr, and xmlFormatData().

        {
                // open file
                if (!($fp = @fopen($file,"w+")))
                {
                        die ("<b>Error</b>: Could not open \"".$file."\" for writing".
                                        " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
                }
                
                // set file permissions
                chmod($file, 0770);
                
                // format xml data
                if ($format)
                {
                        $xmlStr = $this->xmlFormatData($this->xmlStr);
                }
                else
                {
                        $xmlStr = $this->xmlStr;
                }
                
                // write xml data into the file
                fwrite($fp, $xmlStr);
                
                // close file
                fclose($fp);
        }

Here is the call graph for this function:

ilXmlWriter::xmlDumpMem ( format = TRUE  ) 

Returns xml document from memory.

Parameters:
boolean indent text (TRUE) or not (FALSE)
Returns:
string xml document public

Definition at line 506 of file class.ilXmlWriter.php.

References $xmlStr, and xmlFormatData().

Referenced by ilXMLResultSetWriter::getXML(), ilSoapUserObjectXMLWriter::getXML(), ilSoapStructureObjectXMLWriter::getXML(), ilSoapRoleObjectXMLWriter::getXML(), ilObjectXMLWriter::getXML(), ilMD2XML::getXML(), ilCourseXMLWriter::getXML(), ilGroupXMLWriter::getXML(), and ilnetucateXMLAPI::sendRequest().

        {
                // format xml data
                if ($format)
                {
                        $xmlStr = $this->xmlFormatData($this->xmlStr);
                }
                else
                {
                        $xmlStr = $this->xmlStr;
                }
                
                return $xmlStr;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilXmlWriter::xmlElement ( tag,
attrs = NULL,
data = Null,
encode = TRUE,
escape = TRUE 
)

Writes a basic element (no children, just textual content).

Parameters:
string tag name
array attributes (name => value)
string data
boolean ecode attributes' values and data (TRUE) or not (FALSE)
boolean escape attributes' values and data (TRUE) or not (FALSE) public

Definition at line 443 of file class.ilXmlWriter.php.

References $data, xmlData(), xmlEndTag(), and xmlStartTag().

Referenced by ilSoapUserObjectXMLWriter::__addElement(), ilObjectXMLWriter::__appendObject(), ilObjectXMLWriter::__appendOperations(), ilXMLResultSetWriter::__appendRow(), ilGroupXMLWriter::__buildAdmin(), ilXMLResultSetWriter::__buildColSpecs(), ilGroupXMLWriter::__buildMember(), ilCourseXMLWriter::__buildObject(), ilGroupXMLWriter::__buildRegistration(), ilCourseXMLWriter::__buildSetting(), ilGroupXMLWriter::__buildTitleDescription(), ilSoapUserObjectXMLWriter::__handleUser(), and ilSoapRoleObjectXMLWriter::start().

        {
                // check for existing data (element's content)
                if (is_string($data) or
                        is_integer($data))
                {
                        // write starttag
                        $this->xmlStartTag($tag, $attrs, FALSE, $encode, $escape);
                        
                        // write text
                        $this->xmlData($data, $encode, $escape);
                        
                        // write endtag
                        $this->xmlEndTag($tag);
                }
                else // no data
                {
                        // write starttag (= empty tag)
                        $this->xmlStartTag($tag, $attrs, TRUE, $encode, $escape);
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilXmlWriter::xmlEncodeData ( data  ) 

Encodes text from input encoding into output encoding.

Parameters:
string input text
Returns:
string encoded text private

Definition at line 205 of file class.ilXmlWriter.php.

References $data.

Referenced by xmlData(), and xmlStartTag().

        {
                if ($this->inEnc == $this->outEnc)
                {
                        $encodedData = $data;
                }
                else
                {
                        switch(strtolower($this->outEnc))
                        {
                                case "utf-8":
                                        if(strtolower($this->inEnc) == "iso-8859-1")
                                        {
                                                $encodedData = utf8_encode($data);
                                        }
                                        else
                                        {
                                                die ("<b>Error</b>: Cannot encode iso-8859-1 data in ".$this->outEnc.
                                                                " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
                                        }
                                        break;
                                
                                case "iso-8859-1":
                                        if(strtolower($this->inEnc) == "utf-8")
                                        {
                                                $encodedData = utf8_decode($data);
                                        }
                                        else
                                        {
                                                die ("<b>Error</b>: Cannot encode utf-8 data in ".$this->outEnc.
                                                                " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
                                        }
                                        break;
                                        
                                default:
                                        die ("<b>Error</b>: Cannot encode ".$this->inEnc." data in ".$this->outEnc.
                                                        " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
                        }
                }
                return $encodedData;
        }

Here is the caller graph for this function:

ilXmlWriter::xmlEndTag ( tag  ) 

Writes an endtag.

Parameters:
string tag name public

Definition at line 395 of file class.ilXmlWriter.php.

Referenced by ilObjectXMLWriter::__appendObject(), ilXMLResultSetWriter::__appendRow(), ilCourseXMLWriter::__buildAdmin(), ilXMLResultSetWriter::__buildColSpecs(), ilXMLResultSetWriter::__buildFooter(), ilSoapUserObjectXMLWriter::__buildFooter(), ilSoapRoleObjectXMLWriter::__buildFooter(), ilObjectXMLWriter::__buildFooter(), ilCourseXMLWriter::__buildFooter(), ilGroupXMLWriter::__buildFooter(), ilCourseXMLWriter::__buildMember(), ilCourseXMLWriter::__buildObject(), ilGroupXMLWriter::__buildRegistration(), ilXMLResultSetWriter::__buildRows(), ilCourseXMLWriter::__buildSetting(), ilCourseXMLWriter::__buildSubscriber(), ilCourseXMLWriter::__buildTutor(), ilCourseXMLWriter::__buildWaitingList(), ilSoapUserObjectXMLWriter::__handleUser(), ilnetucateXMLAPI::addClass(), ilnetucateXMLAPI::addCourse(), ilnetucateXMLAPI::addUser(), ilnetucateXMLAPI::addUserOLD(), ilnetucateXMLAPI::editClass(), ilnetucateXMLAPI::editCourse(), ilnetucateXMLAPI::editUser(), ilnetucateXMLAPI::findClass(), ilnetucateXMLAPI::findCourseClasses(), ilnetucateXMLAPI::findRegisteredUsersByRole(), ilnetucateXMLAPI::findUser(), ilnetucateXMLAPI::joinClass(), ilnetucateXMLAPI::registerUser(), ilnetucateXMLAPI::removeClass(), ilnetucateXMLAPI::removeCourse(), ilnetucateXMLAPI::removeUser(), ilSoapRoleObjectXMLWriter::start(), ilnetucateXMLAPI::unregisterUser(), ilnetucateXMLAPI::uploadPicture(), ilnetucateXMLAPI::userLogin(), and xmlElement().

        {
                $this->xmlStr .= "</".$tag.">";
        }

Here is the caller graph for this function:

ilXmlWriter::xmlFormatData ( data  ) 

Indents text for better reading.

Parameters:
string input text
Returns:
string indented text private

Reimplemented in ilnetucateXMLAPI.

Definition at line 253 of file class.ilXmlWriter.php.

References $data.

Referenced by xmlDumpFile(), and xmlDumpMem().

        {
                // regular expression for tags
                $formatedXml = preg_replace_callback("|<[^>]*>[^<]*|", array($this, "xmlFormatElement"), $data);
                
                return $formatedXml;
        }

Here is the caller graph for this function:

ilXmlWriter::xmlFormatElement ( array  ) 

Callback function for xmlFormatData; do not invoke directly.

Parameters:
array result of reg. expr. search
Returns:
string indented substring private

Definition at line 267 of file class.ilXmlWriter.php.

References $tab.

        {
                $found = trim($array[0]);
                
                static $indent;
                
                // linebreak (default)
                $nl = "\n";
                
                $tab = str_repeat(" ", $indent * 2);
                
                // closing tag
                if (substr($found, 0, 2) == "</")
                {
                        if($indent)
                        {
                                $indent --;
                        }
                        $tab = str_repeat(" ", $indent * 2);
                }
                elseif (substr($found, -2, 1) == "/" or // opening and closing, comment, ...
                                strpos($found, "/>") or
                                substr($found, 0, 2) == "<!") 
                {
                        // do not change indent
                }
                elseif (substr($found, 0, 2) == "<?") 
                {
                        // do not change indent
                        // no linebreak
                        $nl = "";
                }
                else // opening tag
                {
                        $indent ++;
                }
                
                // content
                if (substr($found, -1) != ">")
                {
                        $found = str_replace(">", ">\n".str_repeat(" ", ($indent + 0) * 2), $found);
                }
                
                return $nl.$tab.$found;
        }

ilXmlWriter::xmlHeader (  ) 

Writes xml header public.

Definition at line 317 of file class.ilXmlWriter.php.

References $xmlStr, and xmlComment().

Referenced by ilXMLResultSetWriter::__buildHeader(), ilSoapUserObjectXMLWriter::__buildHeader(), ilSoapStructureObjectXMLWriter::__buildHeader(), ilSoapRoleObjectXMLWriter::__buildHeader(), ilObjectXMLWriter::__buildHeader(), ilCourseXMLWriter::__buildHeader(), ilGroupXMLWriter::__buildHeader(), ilnetucateXMLAPI::addClass(), ilnetucateXMLAPI::addCourse(), ilnetucateXMLAPI::addUser(), ilnetucateXMLAPI::addUserOLD(), ilnetucateXMLAPI::editClass(), ilnetucateXMLAPI::editCourse(), ilnetucateXMLAPI::editUser(), ilnetucateXMLAPI::findClass(), ilnetucateXMLAPI::findCourseClasses(), ilnetucateXMLAPI::findRegisteredUsersByRole(), ilnetucateXMLAPI::findUser(), ilnetucateXMLAPI::joinClass(), ilnetucateXMLAPI::registerUser(), ilnetucateXMLAPI::removeClass(), ilnetucateXMLAPI::removeCourse(), ilnetucateXMLAPI::removeUser(), ilnetucateXMLAPI::unregisterUser(), ilnetucateXMLAPI::uploadPicture(), and ilnetucateXMLAPI::userLogin().

        {
                // version and encoding
                $this->xmlStr .= "<?xml version=\"".$this->version."\" encoding=\"".$this->outEnc."\"?>";
                
                // dtd definition
                if ($this->dtdDef <> "")
                {
                        $this->xmlStr .= $this->dtdDef;
                }
                
                // stSheet
                if ($this->stSheet <> "")
                {
                        $this->xmlStr .= $this->stSheet;
                }
                
                // generated comment
                if ($this->genCmt <> "")
                {
                        $this->xmlComment($this->genCmt);
                }
                
                return $xmlStr;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilXmlWriter::xmlSetDtdDef ( dtdDef  ) 

Sets dtd definition.

Parameters:
string dtd definition public

Definition at line 121 of file class.ilXmlWriter.php.

References $dtdDef.

Referenced by ilXMLResultSetWriter::__buildHeader(), ilSoapUserObjectXMLWriter::__buildHeader(), ilSoapStructureObjectXMLWriter::__buildHeader(), ilSoapRoleObjectXMLWriter::__buildHeader(), ilObjectXMLWriter::__buildHeader(), and ilGroupXMLWriter::__buildHeader().

        {
                $this->dtdDef = $dtdDef;
        }

Here is the caller graph for this function:

ilXmlWriter::xmlSetGenCmt ( genCmt  ) 

Sets generated comment.

Parameters:
string generated comment public

Definition at line 141 of file class.ilXmlWriter.php.

References $genCmt.

Referenced by ilSoapUserObjectXMLWriter::__buildHeader(), ilSoapStructureObjectXMLWriter::__buildHeader(), ilSoapRoleObjectXMLWriter::__buildHeader(), ilObjectXMLWriter::__buildHeader(), ilCourseXMLWriter::__buildHeader(), and ilGroupXMLWriter::__buildHeader().

        {
                $this->genCmt = $genCmt;
        }

Here is the caller graph for this function:

ilXmlWriter::xmlSetStSheet ( stSheet  ) 

Sets stylesheet.

Parameters:
string stylesheet public

Definition at line 131 of file class.ilXmlWriter.php.

References $stSheet.

        {
                $this->stSheet = $stSheet;
        }

ilXmlWriter::xmlStartTag ( tag,
attrs = NULL,
empty = FALSE,
encode = TRUE,
escape = TRUE 
)

Writes a starttag.

Parameters:
string tag name
array attributes (name => value)
boolean tag empty (TRUE) or not (FALSE)
boolean ecode attributes' values (TRUE) or not (FALSE)
boolean escape attributes' values (TRUE) or not (FALSE) public

Definition at line 352 of file class.ilXmlWriter.php.

References _xmlEscapeData(), and xmlEncodeData().

Referenced by ilObjectXMLWriter::__appendObject(), ilXMLResultSetWriter::__appendRow(), ilCourseXMLWriter::__buildAdmin(), ilXMLResultSetWriter::__buildColSpecs(), ilXMLResultSetWriter::__buildHeader(), ilSoapUserObjectXMLWriter::__buildHeader(), ilSoapRoleObjectXMLWriter::__buildHeader(), ilObjectXMLWriter::__buildHeader(), ilCourseXMLWriter::__buildHeader(), ilGroupXMLWriter::__buildHeader(), ilCourseXMLWriter::__buildMember(), ilCourseXMLWriter::__buildObject(), ilGroupXMLWriter::__buildRegistration(), ilXMLResultSetWriter::__buildRows(), ilCourseXMLWriter::__buildSetting(), ilCourseXMLWriter::__buildSubscriber(), ilCourseXMLWriter::__buildTutor(), ilCourseXMLWriter::__buildWaitingList(), ilSoapUserObjectXMLWriter::__handleUser(), ilnetucateXMLAPI::addClass(), ilnetucateXMLAPI::addCourse(), ilnetucateXMLAPI::addUser(), ilnetucateXMLAPI::addUserOLD(), ilnetucateXMLAPI::editClass(), ilnetucateXMLAPI::editCourse(), ilnetucateXMLAPI::editUser(), ilnetucateXMLAPI::findClass(), ilnetucateXMLAPI::findCourseClasses(), ilnetucateXMLAPI::findRegisteredUsersByRole(), ilnetucateXMLAPI::findUser(), ilnetucateXMLAPI::joinClass(), ilnetucateXMLAPI::registerUser(), ilnetucateXMLAPI::removeClass(), ilnetucateXMLAPI::removeCourse(), ilnetucateXMLAPI::removeUser(), ilSoapRoleObjectXMLWriter::start(), ilnetucateXMLAPI::unregisterUser(), ilnetucateXMLAPI::uploadPicture(), ilnetucateXMLAPI::userLogin(), and xmlElement().

        {
                // write first part of the starttag
                $this->xmlStr .= "<".$tag;
                
                // check for existing attributes
                if (is_array($attrs))
                {
                        // write attributes
                        foreach ($attrs as $name => $value)
                        {
                                // encode
                                if ($encode)
                                {
                                $value = $this->xmlEncodeData($value);
                                }
                                
                                // escape
                                if ($escape)
                                {
                                        $value = ilXmlWriter::_xmlEscapeData($value);
                        }
                                
                                $this->xmlStr .= " ".$name."=\"".$value."\"";
                        }
                }
                
                // write last part of the starttag
                if ($empty)
                {
                        $this->xmlStr .= "/>";
                }
                else
                {
                        $this->xmlStr .= ">";
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

ilXmlWriter::$dtdDef = ""

Definition at line 72 of file class.ilXmlWriter.php.

Referenced by xmlSetDtdDef().

ilXmlWriter::$genCmt = "Generated by ILIAS XmlWriter"

Definition at line 86 of file class.ilXmlWriter.php.

Referenced by xmlSetGenCmt().

ilXmlWriter::$inEnc

Definition at line 65 of file class.ilXmlWriter.php.

Referenced by ilXmlWriter().

ilXmlWriter::$outEnc

Definition at line 58 of file class.ilXmlWriter.php.

Referenced by ilXmlWriter().

ilXmlWriter::$stSheet = ""

Definition at line 79 of file class.ilXmlWriter.php.

Referenced by xmlSetStSheet().

ilXmlWriter::$version

Definition at line 51 of file class.ilXmlWriter.php.

Referenced by ilXmlWriter().

ilXmlWriter::$xmlStr

Definition at line 44 of file class.ilXmlWriter.php.

Referenced by xmlDumpFile(), xmlDumpMem(), and xmlHeader().


The documentation for this class was generated from the following file: