ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\Xml\Writer Class Reference

The XML Writer class. More...

+ Inheritance diagram for Sabre\Xml\Writer:
+ Collaboration diagram for Sabre\Xml\Writer:

Public Member Functions

 write ($value)
 Writes a value to the output stream. More...
 
 startElement ($name)
 Opens a new element. More...
 
 writeElement ($name, $content=null)
 Write a full element tag and it's contents. More...
 
 writeAttributes (array $attributes)
 Writes a list of attributes. More...
 
 writeAttribute ($name, $value)
 Writes a new attribute. More...
 

Protected Attributes

 $adhocNamespaces = []
 
 $namespacesWritten = false
 

Detailed Description

The XML Writer class.

This class works exactly as PHP's built-in XMLWriter, with a few additions.

Namespaces can be registered beforehand, globally. When the first element is written, namespaces will automatically be declared.

The writeAttribute, startElement and writeElement can now take a clark-notation element name (example: {http://www.w3.org/2005/Atom}link).

If, when writing the namespace is a known one a prefix will automatically be selected, otherwise a random prefix will be generated.

Instead of standard string values, the writer can take Element classes (as defined by this library) to delegate the serialization.

The write() method can take array structures to quickly write out simple xml trees.

Author
Evert Pot (http://evertpot.com/) @license http://sabre.io/license/ Modified BSD License

Definition at line 31 of file Writer.php.

Member Function Documentation

◆ startElement()

Sabre\Xml\Writer::startElement (   $name)

Opens a new element.

You can either just use a local elementname, or you can use clark- notation to start a new element.

Example:

$writer->startElement('{http://www.w3.org/2005/Atom}entry');

Would result in something like:

<entry xmlns="http://w3.org/2005/Atom">
Parameters
string$name
Returns
bool

Definition at line 121 of file Writer.php.

121 {
122
123 if ($name[0] === '{') {
124
125 list($namespace, $localName) =
127
128 if (array_key_exists($namespace, $this->namespaceMap)) {
129 $result = $this->startElementNS(
130 $this->namespaceMap[$namespace] === '' ? null : $this->namespaceMap[$namespace],
131 $localName,
132 null
133 );
134 } else {
135
136 // An empty namespace means it's the global namespace. This is
137 // allowed, but it mustn't get a prefix.
138 if ($namespace === "" || $namespace === null) {
139 $result = $this->startElement($localName);
140 $this->writeAttribute('xmlns', '');
141 } else {
142 if (!isset($this->adhocNamespaces[$namespace])) {
143 $this->adhocNamespaces[$namespace] = 'x' . (count($this->adhocNamespaces) + 1);
144 }
145 $result = $this->startElementNS($this->adhocNamespaces[$namespace], $localName, $namespace);
146 }
147 }
148
149 } else {
150 $result = parent::startElement($name);
151 }
152
153 if (!$this->namespacesWritten) {
154
155 foreach ($this->namespaceMap as $namespace => $prefix) {
156 $this->writeAttribute(($prefix ? 'xmlns:' . $prefix : 'xmlns'), $namespace);
157 }
158 $this->namespacesWritten = true;
159
160 }
161
162 return $result;
163
164 }
$result
static parseClarkNotation($str)
Parses a clark-notation string, and returns the namespace and element name components.
Definition: Service.php:274
writeAttribute($name, $value)
Writes a new attribute.
Definition: Writer.php:230
startElement($name)
Opens a new element.
Definition: Writer.php:121
if($err=$client->getError()) $namespace

References $name, $namespace, $result, Sabre\Xml\Service\parseClarkNotation(), Sabre\Xml\Writer\startElement(), and Sabre\Xml\Writer\writeAttribute().

Referenced by Sabre\DAVACL\Xml\Property\Acl\serializeAce(), Sabre\DAVACL\Xml\Property\SupportedPrivilegeSet\serializePriv(), Sabre\Xml\Serializer\standardSerializer(), Sabre\Xml\Writer\startElement(), Sabre\Xml\Writer\writeElement(), Sabre\CalDAV\Xml\Notification\SystemStatus\xmlSerialize(), Sabre\CalDAV\Xml\Property\Invite\xmlSerialize(), Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet\xmlSerialize(), Sabre\CalDAV\Xml\Property\SupportedCalendarData\xmlSerialize(), Sabre\CardDAV\Xml\Property\SupportedAddressData\xmlSerialize(), Sabre\DAV\Xml\Element\Response\xmlSerialize(), Sabre\DAV\Xml\Property\LockDiscovery\xmlSerialize(), Sabre\DAV\Xml\Property\SupportedMethodSet\xmlSerialize(), Sabre\DAV\Xml\Property\SupportedReportSet\xmlSerialize(), Sabre\DAV\Xml\Request\PropPatch\xmlSerialize(), Sabre\DAVACL\Xml\Property\CurrentUserPrivilegeSet\xmlSerialize(), Sabre\Xml\Element\XmlFragment\xmlSerialize(), Sabre\CalDAV\Xml\Notification\Invite\xmlSerializeFull(), Sabre\CalDAV\Xml\Notification\InviteReply\xmlSerializeFull(), and Sabre\CalDAV\Xml\Notification\SystemStatus\xmlSerializeFull().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write()

Sabre\Xml\Writer::write (   $value)

Writes a value to the output stream.

The following values are supported:

  1. Scalar values will be written as-is, as text.
  2. Null values will be skipped (resulting in a short xml tag).
  3. If a value is an instance of an Element class, writing will be delegated to the object.
  4. If a value is an array, two formats are supported.

Array format 1: [ "{namespace}name1" => "..", "{namespace}name2" => "..", ]

One element will be created for each key in this array. The values of this array support any format this method supports (this method is called recursively).

Array format 2:

[ [ "name" => "{namespace}name1" "value" => "..", "attributes" => [ "attr" => "attribute value", ] ], [ "name" => "{namespace}name1" "value" => "..", "attributes" => [ "attr" => "attribute value", ] ] ]

Parameters
mixed$value
Returns
void

Definition at line 98 of file Writer.php.

98 {
99
100 Serializer\standardSerializer($this, $value);
101
102 }
standardSerializer(Writer $writer, $value)
This function is the 'default' serializer that is able to serialize most things, and delegates to oth...
Definition: functions.php:164

References Sabre\Xml\Serializer\standardSerializer().

Referenced by Sabre\Xml\Serializer\standardSerializer(), Sabre\Xml\Writer\writeElement(), Sabre\DAV\Xml\Element\Sharee\xmlSerialize(), Sabre\DAV\Xml\Property\GetLastModified\xmlSerialize(), and Sabre\DAV\Xml\Request\PropPatch\xmlSerialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeAttribute()

Sabre\Xml\Writer::writeAttribute (   $name,
  $value 
)

Writes a new attribute.

The name may be specified in clark-notation.

Returns true when successful.

Parameters
string$name
string$value
Returns
bool

Definition at line 230 of file Writer.php.

230 {
231
232 if ($name[0] === '{') {
233
234 list(
236 $localName
238
239 if (array_key_exists($namespace, $this->namespaceMap)) {
240 // It's an attribute with a namespace we know
241 $this->writeAttribute(
242 $this->namespaceMap[$namespace] . ':' . $localName,
243 $value
244 );
245 } else {
246
247 // We don't know the namespace, we must add it in-line
248 if (!isset($this->adhocNamespaces[$namespace])) {
249 $this->adhocNamespaces[$namespace] = 'x' . (count($this->adhocNamespaces) + 1);
250 }
251 $this->writeAttributeNS(
252 $this->adhocNamespaces[$namespace],
253 $localName,
255 $value
256 );
257
258 }
259
260 } else {
261 return parent::writeAttribute($name, $value);
262 }
263
264 }

References $name, $namespace, Sabre\Xml\Service\parseClarkNotation(), and Sabre\Xml\Writer\writeAttribute().

Referenced by Sabre\Xml\Writer\startElement(), Sabre\Xml\Writer\writeAttribute(), Sabre\Xml\Writer\writeAttributes(), Sabre\CalDAV\Xml\Notification\SystemStatus\xmlSerialize(), Sabre\DAV\Xml\Property\SupportedMethodSet\xmlSerialize(), Sabre\Xml\Element\XmlFragment\xmlSerialize(), and Sabre\CalDAV\Xml\Notification\SystemStatus\xmlSerializeFull().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeAttributes()

Sabre\Xml\Writer::writeAttributes ( array  $attributes)

Writes a list of attributes.

Attributes are specified as a key->value array.

The key is an attribute name. If the key is a 'localName', the current xml namespace is assumed. If it's a 'clark notation key', this namespace will be used instead.

Parameters
array$attributes
Returns
void

Definition at line 211 of file Writer.php.

211 {
212
213 foreach ($attributes as $name => $value) {
214 $this->writeAttribute($name, $value);
215 }
216
217 }
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85

References $attributes, $name, and Sabre\Xml\Writer\writeAttribute().

Referenced by Sabre\Xml\Serializer\standardSerializer(), Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet\xmlSerialize(), Sabre\CalDAV\Xml\Property\SupportedCalendarData\xmlSerialize(), and Sabre\CardDAV\Xml\Property\SupportedAddressData\xmlSerialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeElement()

Sabre\Xml\Writer::writeElement (   $name,
  $content = null 
)

Write a full element tag and it's contents.

This method automatically closes the element as well.

The element name may be specified in clark-notation.

Examples:

$writer->writeElement('{http://www.w3.org/2005/Atom}author',null); becomes: <author xmlns="http://www.w3.org/2005" >

$writer->writeElement('{http://www.w3.org/2005/Atom}author', [ '{http://www.w3.org/2005/Atom}name' => 'Evert Pot', ]); becomes: <author xmlns="http://www.w3.org/2005" ><name>Evert Pot</name></author>

Parameters
string$name
string$content
Returns
bool

Definition at line 189 of file Writer.php.

189 {
190
191 $this->startElement($name);
192 if (!is_null($content)) {
193 $this->write($content);
194 }
195 $this->endElement();
196
197 }
write($value)
Writes a value to the output stream.
Definition: Writer.php:98

References $name, Sabre\Xml\Writer\startElement(), and Sabre\Xml\Writer\write().

Referenced by Sabre\Xml\Serializer\enum(), Sabre\Xml\Serializer\repeatingElements(), Sabre\DAVACL\Xml\Property\Acl\serializeAce(), Sabre\DAVACL\Xml\Property\SupportedPrivilegeSet\serializePriv(), Sabre\Xml\Serializer\valueObject(), Sabre\CalDAV\Xml\Notification\Invite\xmlSerialize(), Sabre\CalDAV\Xml\Notification\InviteReply\xmlSerialize(), Sabre\CalDAV\Xml\Property\AllowedSharingModes\xmlSerialize(), Sabre\CalDAV\Xml\Property\EmailAddressSet\xmlSerialize(), Sabre\CalDAV\Xml\Property\Invite\xmlSerialize(), Sabre\CalDAV\Xml\Property\ScheduleCalendarTransp\xmlSerialize(), Sabre\CalDAV\Xml\Property\SupportedCollationSet\xmlSerialize(), Sabre\CardDAV\Xml\Property\SupportedCollationSet\xmlSerialize(), Sabre\DAV\Xml\Element\Response\xmlSerialize(), Sabre\DAV\Xml\Element\Sharee\xmlSerialize(), Sabre\DAV\Xml\Property\Href\xmlSerialize(), Sabre\DAV\Xml\Property\Invite\xmlSerialize(), Sabre\DAV\Xml\Property\LockDiscovery\xmlSerialize(), Sabre\DAV\Xml\Property\ShareAccess\xmlSerialize(), Sabre\DAV\Xml\Property\SupportedLock\xmlSerialize(), Sabre\DAV\Xml\Property\SupportedReportSet\xmlSerialize(), Sabre\DAV\Xml\Response\MultiStatus\xmlSerialize(), Sabre\DAVACL\Xml\Property\AclRestrictions\xmlSerialize(), Sabre\DAVACL\Xml\Property\CurrentUserPrivilegeSet\xmlSerialize(), Sabre\DAVACL\Xml\Property\Principal\xmlSerialize(), Sabre\CalDAV\Xml\Notification\Invite\xmlSerializeFull(), Sabre\CalDAV\Xml\Notification\InviteReply\xmlSerializeFull(), and Sabre\CalDAV\Xml\Notification\SystemStatus\xmlSerializeFull().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $adhocNamespaces

Sabre\Xml\Writer::$adhocNamespaces = []
protected

Definition at line 44 of file Writer.php.

◆ $namespacesWritten

Sabre\Xml\Writer::$namespacesWritten = false
protected

Definition at line 54 of file Writer.php.


The documentation for this class was generated from the following file: