public static function RestWSFormatXML::addToXML in RESTful Web Services 7
Same name and namespace in other branches
- 7.2 restws.formats.inc \RestWSFormatXML::addToXML()
Adds the data of the given wrapper to the given XML element.
1 call to RestWSFormatXML::addToXML()
- RestWSFormatXML::viewResource in ./
restws.formats.inc - Gets the representation of a resource.
File
- ./
restws.formats.inc, line 267 - RESTful web services module formats.
Class
- RestWSFormatXML
- A formatter for XML.
Code
public static function addToXML(DOMDocument $doc, DOMNode $parent, $wrapper) {
$filtered = restws_property_access_filter($wrapper);
foreach ($filtered as $name => $property) {
try {
if ($property instanceof EntityDrupalWrapper) {
// For referenced entities only return the URI.
if ($id = $property
->getIdentifier()) {
$element = $doc
->createElement(is_numeric($name) ? 'item' : $name);
$parent
->appendChild($element);
self::setXMLReference($element, $property
->type(), $id);
}
}
elseif ($property instanceof EntityValueWrapper) {
$escaped = $doc
->createTextNode($property
->value());
$element = $doc
->createElement(is_numeric($name) ? 'item' : $name);
$element
->appendChild($escaped);
$parent
->appendChild($element);
}
elseif ($property instanceof EntityListWrapper || $property instanceof EntityStructureWrapper) {
$element = $doc
->createElement(is_numeric($name) ? 'item' : $name);
$parent
->appendChild($element);
self::addToXML($doc, $element, $property);
}
} catch (EntityMetadataWrapperException $e) {
// A property causes problems - ignore that.
}
}
}