ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 include_once "./Services/Xml/classes/class.ilXmlWriter.php";
6 
14 {
15  public $xmlResultSet;
16 
17  public function __construct(&$xmlResultSet)
18  {
19  parent::__construct();
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 }
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
XML Writer for XMLResultSet.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
xmlDumpMem($format=true)
Returns xml document from memory.
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlHeader()
Writes xml header public.
Create styles array
The data for the language used.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)