private function XmlEncoder::parseXmlValue in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/serializer/Encoder/XmlEncoder.php \Symfony\Component\Serializer\Encoder\XmlEncoder::parseXmlValue()
Parse the input DOMNode value (content and children) into an array or a string.
Parameters
\DOMNode $node xml to parse:
Return value
array|string
1 call to XmlEncoder::parseXmlValue()
- XmlEncoder::parseXml in vendor/
symfony/ serializer/ Encoder/ XmlEncoder.php - Parse the input DOMNode into an array or a string.
File
- vendor/
symfony/ serializer/ Encoder/ XmlEncoder.php, line 319
Class
- XmlEncoder
- Encodes XML data.
Namespace
Symfony\Component\Serializer\EncoderCode
private function parseXmlValue(\DOMNode $node) {
if (!$node
->hasChildNodes()) {
return $node->nodeValue;
}
if (1 === $node->childNodes->length && in_array($node->firstChild->nodeType, array(
XML_TEXT_NODE,
XML_CDATA_SECTION_NODE,
))) {
return $node->firstChild->nodeValue;
}
$value = array();
foreach ($node->childNodes as $subnode) {
$val = $this
->parseXml($subnode);
if ('item' === $subnode->nodeName && isset($val['@key'])) {
if (isset($val['#'])) {
$value[$val['@key']] = $val['#'];
}
else {
$value[$val['@key']] = $val;
}
}
else {
$value[$subnode->nodeName][] = $val;
}
}
foreach ($value as $key => $val) {
if (is_array($val) && 1 === count($val)) {
$value[$key] = current($val);
}
}
return $value;
}