ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
16 
17  function __construct(& $xmlResultSet)
18  {
19  parent::__construct();
20  $this->xmlResultSet = $xmlResultSet;
21  }
22 
23 
24  function start()
25  {
26  if(!is_object($this->xmlResultSet))
27  {
28  return false;
29  }
30 
31  $this->__buildHeader();
32 
33  $this->__buildColSpecs();
34 
35  $this->__buildRows();
36 
37  $this->__buildFooter();
38 
39  return true;
40  }
41 
42  function getXML()
43  {
44  return $this->xmlDumpMem(FALSE);
45  }
46 
47 
48  // PRIVATE
49  function __appendRow(& $xmlResultSetRow)
50  {
51  $this->xmlStartTag('row',null);
52 
53  foreach ($xmlResultSetRow->getColumns() as $value)
54  {
55  $this->xmlElement('column',null,$value);
56 
57  }
58 
59  $this->xmlEndTag('row');
60 
61  }
62 
63 
64  function __buildHeader()
65  {
66  $this->xmlSetDtdDef("<!DOCTYPE result PUBLIC \"-//ILIAS//DTD XMLResultSet//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_xml_resultset_3_7.dtd\">");
67  $this->xmlHeader();
68 
69  $this->xmlStartTag("result");
70 
71  return true;
72  }
73 
74  function __buildColSpecs() {
75  $this->xmlStartTag("colspecs");
76 
77  foreach ($this->xmlResultSet->getColSpecs() as $colSpec) {
78  $attr = array ("idx" => $colSpec->getIndex(), "name" => $colSpec->getName());
79 
80  $this->xmlElement("colspec", $attr, null);
81  }
82 
83  $this->xmlEndTag("colspecs");
84  }
85 
86  function __buildRows () {
87  $this->xmlStartTag("rows");
88 
89  foreach($this->xmlResultSet->getRows() as $row)
90  {
91  $this->__appendRow($row);
92  }
93 
94  $this->xmlEndTag("rows");
95  }
96 
97  function __buildFooter()
98  {
99  $this->xmlEndTag('result');
100  }
101 
102 
103 
104 }
105 
106 
107 ?>
XML Writer for XMLResultSet.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
xmlEndTag($tag)
Writes an endtag.
xmlHeader()
Writes xml header public.
Create styles array
The data for the language used.
xmlDumpMem($format=TRUE)
Returns xml document from memory.