ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilXmlWriter Class Reference

XML writer class. More...

+ Inheritance diagram for ilXmlWriter:
+ Collaboration 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 matth.nosp@m.ias..nosp@m.rulin.nosp@m.ski@.nosp@m.mi.un.nosp@m.i-ko.nosp@m.eln.d.nosp@m.e
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
stringinput 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" 
)
ilXmlWriter::xmlComment (   $comment)

Writes a comment.

Parameters
stringcomment 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
stringdata
stringecode data (TRUE) or not (FALSE)
stringescape 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)
{
}
// escape
if ($escape)
{
}
$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
stringfile name (full path)
booleanindent 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
{
}
// 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
booleanindent 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 ilSoapInstallationInfoXMLWriter\getXML(), ilMD2XML\getXML(), ilXMLResultSetWriter\getXML(), ilGroupXMLWriter\getXML(), ilSoapStructureObjectXMLWriter\getXML(), ilCourseXMLWriter\getXML(), ilObjectXMLWriter\getXML(), ilUserXMLWriter\getXML(), ilSoapRoleObjectXMLWriter\getXML(), ilFileXMLWriter\getXML(), ilExerciseXMLWriter\getXML(), and ilnetucateXMLAPI\sendRequest().

{
// format xml data
if ($format)
{
$xmlStr = $this->xmlFormatData($this->xmlStr);
}
else
{
}
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
stringtag name
arrayattributes (name => value)
stringdata
booleanecode attributes' values and data (TRUE) or not (FALSE)
booleanescape 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 ilUserXMLWriter\__addElement(), ilObjectXMLWriter\__appendObject(), ilObjectXMLWriter\__appendOperations(), ilXMLResultSetWriter\__appendRow(), ilGroupXMLWriter\__buildAdmin(), ilSoapInstallationInfoXMLWriter\__buildClient(), ilXMLResultSetWriter\__buildColSpecs(), ilSoapInstallationInfoXMLWriter\__buildInstallationInfo(), ilGroupXMLWriter\__buildMember(), ilCourseXMLWriter\__buildObject(), ilGroupXMLWriter\__buildRegistration(), ilCourseXMLWriter\__buildSetting(), ilGroupXMLWriter\__buildTitleDescription(), ilUserXMLWriter\__handlePreferences(), ilUserXMLWriter\__handleUser(), ilExerciseXMLWriter\attachMarking(), ilSoapRoleObjectXMLWriter\start(), ilFileXMLWriter\start(), ilAdvancedMDRecord\toXML(), and ilAdvancedMDFieldDefinition\toXML().

{
// 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
stringinput 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
stringtag name public

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

Referenced by ilObjectXMLWriter\__appendObject(), ilXMLResultSetWriter\__appendRow(), ilCourseXMLWriter\__buildAdmin(), ilSoapInstallationInfoXMLWriter\__buildClient(), ilXMLResultSetWriter\__buildColSpecs(), ilSoapInstallationInfoXMLWriter\__buildFooter(), ilXMLResultSetWriter\__buildFooter(), ilUserXMLWriter\__buildFooter(), ilSoapRoleObjectXMLWriter\__buildFooter(), ilObjectXMLWriter\__buildFooter(), ilGroupXMLWriter\__buildFooter(), ilCourseXMLWriter\__buildFooter(), ilSoapInstallationInfoXMLWriter\__buildInstallationInfo(), ilCourseXMLWriter\__buildMember(), ilCourseXMLWriter\__buildObject(), ilGroupXMLWriter\__buildRegistration(), ilXMLResultSetWriter\__buildRows(), ilCourseXMLWriter\__buildSetting(), ilCourseXMLWriter\__buildSubscriber(), ilCourseXMLWriter\__buildTutor(), ilCourseXMLWriter\__buildWaitingList(), ilUserXMLWriter\__handlePreferences(), ilUserXMLWriter\__handleUser(), ilAdvancedMDValues\_appendXMLByObjId(), ilnetucateXMLAPI\addClass(), ilnetucateXMLAPI\addCourse(), ilnetucateXMLAPI\addUser(), ilnetucateXMLAPI\addUserOLD(), ilExerciseXMLWriter\attachMarking(), ilnetucateXMLAPI\editClass(), ilnetucateXMLAPI\editCourse(), ilnetucateXMLAPI\editUser(), ilSoapInstallationInfoXMLWriter\end(), ilnetucateXMLAPI\findClass(), ilnetucateXMLAPI\findCourseClasses(), ilnetucateXMLAPI\findRegisteredUsersByRole(), ilnetucateXMLAPI\findUser(), ilnetucateXMLAPI\joinClass(), ilnetucateXMLAPI\registerUser(), ilnetucateXMLAPI\removeClass(), ilnetucateXMLAPI\removeCourse(), ilnetucateXMLAPI\removeUser(), ilSoapRoleObjectXMLWriter\start(), ilFileXMLWriter\start(), ilAdvancedMDRecord\toXML(), ilAdvancedMDFieldDefinition\toXML(), ilnetucateXMLAPI\unregisterUser(), ilnetucateXMLAPI\uploadPicture(), ilnetucateXMLAPI\userLogin(), ilAdvancedMDRecordXMLWriter\write(), and xmlElement().

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

+ Here is the caller graph for this function:

ilXmlWriter::xmlFormatData (   $data)

Indents text for better reading.

Parameters
stringinput 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
arrayresult 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 $dtdDef, $stSheet, $xmlStr, and xmlComment().

Referenced by ilSoapInstallationInfoXMLWriter\__buildHeader(), ilGroupXMLWriter\__buildHeader(), ilXMLResultSetWriter\__buildHeader(), ilSoapStructureObjectXMLWriter\__buildHeader(), ilCourseXMLWriter\__buildHeader(), ilUserXMLWriter\__buildHeader(), ilSoapRoleObjectXMLWriter\__buildHeader(), ilFileXMLWriter\__buildHeader(), ilObjectXMLWriter\__buildHeader(), ilExerciseXMLWriter\__buildHeader(), ilnetucateXMLAPI\addClass(), ilnetucateXMLAPI\addCourse(), ilnetucateXMLAPI\addUser(), ilnetucateXMLAPI\addUserOLD(), ilContObjectExport\buildExportFilePDF(), ilAdvancedMDRecordXMLWriter\buildHeader(), ilContObjectManifestBuilder\buildManifest(), ilnetucateXMLAPI\editClass(), ilnetucateXMLAPI\editCourse(), ilnetucateXMLAPI\editUser(), ilnetucateXMLAPI\findClass(), ilnetucateXMLAPI\findCourseClasses(), ilnetucateXMLAPI\findRegisteredUsersByRole(), ilnetucateXMLAPI\findUser(), ilnetucateXMLAPI\joinClass(), ilnetucateXMLAPI\registerUser(), ilnetucateXMLAPI\removeClass(), ilnetucateXMLAPI\removeCourse(), ilnetucateXMLAPI\removeUser(), assFlashQuestionExport\toXML(), assMultipleChoiceExport\toXML(), assTextQuestionExport\toXML(), assTextSubsetExport\toXML(), assJavaAppletExport\toXML(), assNumericExport\toXML(), assOrderingQuestionExport\toXML(), assSingleChoiceExport\toXML(), assClozeTestExport\toXML(), assMatchingQuestionExport\toXML(), assImagemapQuestionExport\toXML(), SurveyTextQuestion\toXML(), SurveyNominalQuestion\toXML(), SurveyOrdinalQuestion\toXML(), SurveyMetricQuestion\toXML(), ilObjSurveyQuestionPool\toXML(), SurveyMatrixQuestion\toXML(), ilObjSurvey\toXML(), ilObjTest\toXML(), 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::xmlSetStSheet (   $stSheet)

Sets stylesheet.

Parameters
stringstylesheet 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
stringtag name
arrayattributes (name => value)
booleantag empty (TRUE) or not (FALSE)
booleanecode attributes' values (TRUE) or not (FALSE)
booleanescape 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(), ilSoapInstallationInfoXMLWriter\__buildClient(), ilXMLResultSetWriter\__buildColSpecs(), ilSoapInstallationInfoXMLWriter\__buildHeader(), ilGroupXMLWriter\__buildHeader(), ilXMLResultSetWriter\__buildHeader(), ilCourseXMLWriter\__buildHeader(), ilUserXMLWriter\__buildHeader(), ilSoapRoleObjectXMLWriter\__buildHeader(), ilObjectXMLWriter\__buildHeader(), ilSoapInstallationInfoXMLWriter\__buildInstallationInfo(), ilCourseXMLWriter\__buildMember(), ilCourseXMLWriter\__buildObject(), ilGroupXMLWriter\__buildRegistration(), ilXMLResultSetWriter\__buildRows(), ilCourseXMLWriter\__buildSetting(), ilCourseXMLWriter\__buildSubscriber(), ilCourseXMLWriter\__buildTutor(), ilCourseXMLWriter\__buildWaitingList(), ilUserXMLWriter\__handlePreferences(), ilUserXMLWriter\__handleUser(), ilAdvancedMDValues\_appendXMLByObjId(), ilnetucateXMLAPI\addClass(), ilnetucateXMLAPI\addCourse(), ilnetucateXMLAPI\addUser(), ilnetucateXMLAPI\addUserOLD(), ilExerciseXMLWriter\attachMarking(), ilnetucateXMLAPI\editClass(), ilnetucateXMLAPI\editCourse(), ilnetucateXMLAPI\editUser(), ilnetucateXMLAPI\findClass(), ilnetucateXMLAPI\findCourseClasses(), ilnetucateXMLAPI\findRegisteredUsersByRole(), ilnetucateXMLAPI\findUser(), ilnetucateXMLAPI\joinClass(), ilnetucateXMLAPI\registerUser(), ilnetucateXMLAPI\removeClass(), ilnetucateXMLAPI\removeCourse(), ilnetucateXMLAPI\removeUser(), ilSoapInstallationInfoXMLWriter\start(), ilSoapRoleObjectXMLWriter\start(), ilFileXMLWriter\start(), ilAdvancedMDRecord\toXML(), ilAdvancedMDFieldDefinition\toXML(), ilnetucateXMLAPI\unregisterUser(), ilnetucateXMLAPI\uploadPicture(), ilnetucateXMLAPI\userLogin(), ilAdvancedMDRecordXMLWriter\write(), 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 xmlHeader(), and 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 xmlHeader(), and xmlSetStSheet().

ilXmlWriter::$version

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

Referenced by ilXmlWriter(), and ilFileXMLWriter\start().

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: