ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilXMLResultSetWriter.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "./Services/Xml/classes/class.ilXmlWriter.php";
6
14{
16
17 public function __construct(&$xmlResultSet)
18 {
20 $this->xmlResultSet = $xmlResultSet;
21 }
22
23
24 public function start()
25 {
26 if (!is_object($this->xmlResultSet)) {
27 return false;
28 }
29
30 $this->__buildHeader();
31
32 $this->__buildColSpecs();
33
34 $this->__buildRows();
35
36 $this->__buildFooter();
37
38 return true;
39 }
40
41 public function getXML()
42 {
43 return $this->xmlDumpMem(false);
44 }
45
46
47 // PRIVATE
48 public function __appendRow(&$xmlResultSetRow)
49 {
50 $this->xmlStartTag('row', null);
51
52 foreach ($xmlResultSetRow->getColumns() as $value) {
53 $this->xmlElement('column', null, $value);
54 }
55
56 $this->xmlEndTag('row');
57 }
58
59
60 public function __buildHeader()
61 {
62 $this->xmlSetDtdDef("<!DOCTYPE result PUBLIC \"-//ILIAS//DTD XMLResultSet//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_xml_resultset_3_7.dtd\">");
63 $this->xmlHeader();
64
65 $this->xmlStartTag("result");
66
67 return true;
68 }
69
70 public function __buildColSpecs()
71 {
72 $this->xmlStartTag("colspecs");
73
74 foreach ($this->xmlResultSet->getColSpecs() as $colSpec) {
75 $attr = array("idx" => $colSpec->getIndex(), "name" => $colSpec->getName());
76
77 $this->xmlElement("colspec", $attr, null);
78 }
79
80 $this->xmlEndTag("colspecs");
81 }
82
83 public function __buildRows()
84 {
85 $this->xmlStartTag("rows");
86
87 foreach ($this->xmlResultSet->getRows() as $row) {
88 $this->__appendRow($row);
89 }
90
91 $this->xmlEndTag("rows");
92 }
93
94 public function __buildFooter()
95 {
96 $this->xmlEndTag('result');
97 }
98}
An exception for terminatinating execution or to throw for unit testing.
XML Writer for XMLResultSet.
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlDumpMem($format=true)
Returns xml document from memory.
xmlHeader()
Writes xml header @access public.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc