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" | |
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.
Definition at line 37 of file class.ilXmlWriter.php.
| ilXmlWriter::_ilXmlWriter | ( | ) |
destructor public
Definition at line 110 of file class.ilXmlWriter.php.
{
// terminate xml string
unset($this->xmlStr);
}
| 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
| 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(), ilMD2XML::ilMD2XML(), and ilnetucateXMLAPI::ilnetucateXMLAPI().
{
// 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 | ( | ) |
clears xmlStr public
Definition at line 533 of file class.ilXmlWriter.php.
Referenced by ilnetucateXMLAPI::addClass(), ilnetucateXMLAPI::addCourse(), ilnetucateXMLAPI::addUser(), ilnetucateXMLAPI::editClass(), ilnetucateXMLAPI::editCourse(), ilnetucateXMLAPI::findClass(), ilnetucateXMLAPI::findCourseClasses(), ilnetucateXMLAPI::findRegisteredUsersByRole(), ilnetucateXMLAPI::findUser(), ilnetucateXMLAPI::joinClass(), ilnetucateXMLAPI::registerUser(), ilnetucateXMLAPI::removeClass(), ilnetucateXMLAPI::removeCourse(), ilnetucateXMLAPI::removeUser(), ilnetucateXMLAPI::unregisterUser(), and ilnetucateXMLAPI::userLogin().
{
// reset xml string
$this->xmlStr = "";
}
Here is the caller graph for this function:| ilXmlWriter::xmlComment | ( | $ | comment | ) |
Writes a comment.
| 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.
| 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, xmlEncodeData(), and xmlEscapeData().
Referenced by xmlElement().
{
// encode
if ($encode)
{
$data = $this->xmlEncodeData($data);
}
// escape
if ($escape)
{
$data = $this->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.
| 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.
| boolean | indent text (TRUE) or not (FALSE) |
Definition at line 506 of file class.ilXmlWriter.php.
References $xmlStr, and xmlFormatData().
Referenced by ilMD2XML::getXML(), ilCourseXMLWriter::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).
| 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 ilCourseXMLWriter::__buildObject(), and ilCourseXMLWriter::__buildSetting().
{
// 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.
| string | input text |
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.
| string | tag name public |
Definition at line 395 of file class.ilXmlWriter.php.
Referenced by ilCourseXMLWriter::__buildAdmin(), ilCourseXMLWriter::__buildFooter(), ilCourseXMLWriter::__buildMember(), ilCourseXMLWriter::__buildObject(), ilCourseXMLWriter::__buildSetting(), ilCourseXMLWriter::__buildSubscriber(), ilCourseXMLWriter::__buildTutor(), ilnetucateXMLAPI::addClass(), ilnetucateXMLAPI::addCourse(), ilnetucateXMLAPI::addUser(), ilnetucateXMLAPI::editClass(), ilnetucateXMLAPI::editCourse(), ilnetucateXMLAPI::findClass(), ilnetucateXMLAPI::findCourseClasses(), ilnetucateXMLAPI::findRegisteredUsersByRole(), ilnetucateXMLAPI::findUser(), ilnetucateXMLAPI::joinClass(), ilnetucateXMLAPI::registerUser(), ilnetucateXMLAPI::removeClass(), ilnetucateXMLAPI::removeCourse(), ilnetucateXMLAPI::removeUser(), ilnetucateXMLAPI::unregisterUser(), ilnetucateXMLAPI::uploadPicture(), ilnetucateXMLAPI::userLogin(), and xmlElement().
{
$this->xmlStr .= "</".$tag.">";
}
Here is the caller graph for this function:| ilXmlWriter::xmlEscapeData | ( | $ | data | ) |
Escapes reserved characters.
| string | input text |
Definition at line 152 of file class.ilXmlWriter.php.
References $data.
Referenced by 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 = """;
break;
case 38:
$character = "&";
break;
case 39:
$character = "'";
break;
case 60:
$character = "<";
break;
case 62:
$character = ">";
break;
default:
if ($code < 32)
{
$character = ("&#".strval($code).";");
}
break;
}
$escapedData .= $character;
$position ++;
}
return $escapedData;
}
Here is the caller graph for this function:| ilXmlWriter::xmlFormatData | ( | $ | data | ) |
Indents text for better reading.
| string | input text |
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.
| array | result of reg. expr. search |
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 ilCourseXMLWriter::__buildHeader(), ilnetucateXMLAPI::addClass(), ilnetucateXMLAPI::addCourse(), ilnetucateXMLAPI::addUser(), ilnetucateXMLAPI::editClass(), ilnetucateXMLAPI::editCourse(), 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.
| string | dtd definition public |
Definition at line 121 of file class.ilXmlWriter.php.
References $dtdDef.
Referenced by ilCourseXMLWriter::__buildHeader().
{
$this->dtdDef = $dtdDef;
}
Here is the caller graph for this function:| ilXmlWriter::xmlSetGenCmt | ( | $ | genCmt | ) |
Sets generated comment.
| string | generated comment public |
Definition at line 141 of file class.ilXmlWriter.php.
References $genCmt.
Referenced by ilCourseXMLWriter::__buildHeader().
{
$this->genCmt = $genCmt;
}
Here is the caller graph for this function:| ilXmlWriter::xmlSetStSheet | ( | $ | stSheet | ) |
Sets stylesheet.
| 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.
| 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 xmlEncodeData(), and xmlEscapeData().
Referenced by ilCourseXMLWriter::__buildAdmin(), ilCourseXMLWriter::__buildHeader(), ilCourseXMLWriter::__buildMember(), ilCourseXMLWriter::__buildObject(), ilCourseXMLWriter::__buildSetting(), ilCourseXMLWriter::__buildSubscriber(), ilCourseXMLWriter::__buildTutor(), ilnetucateXMLAPI::addClass(), ilnetucateXMLAPI::addCourse(), ilnetucateXMLAPI::addUser(), ilnetucateXMLAPI::editClass(), ilnetucateXMLAPI::editCourse(), ilnetucateXMLAPI::findClass(), ilnetucateXMLAPI::findCourseClasses(), ilnetucateXMLAPI::findRegisteredUsersByRole(), ilnetucateXMLAPI::findUser(), ilnetucateXMLAPI::joinClass(), ilnetucateXMLAPI::registerUser(), ilnetucateXMLAPI::removeClass(), ilnetucateXMLAPI::removeCourse(), ilnetucateXMLAPI::removeUser(), 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 = $this->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:| 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().
1.7.1