Write XML as per Associative Array

@param      XMLWriter  $xml    object
@param      array      $data   Associative Data Array
550036
protected function writeEl(XMLWriter $xml, $data)
    {
        foreach ($data as $key => $value) {
            if (\is_array($value) && !$this->isAssoc($value)) { //numeric array
                foreach ($value as $itemValue) {
                    if (\is_array($itemValue)) {
                        $xml->startElement($key);
                        $itemValue = $this->writeAttr($xml, $itemValue);
                        $this->writeEl($xml, $itemValue);
                        $xml->endElement();
                    } else {
                        $itemValue = $this->writeAttr($xml, $itemValue);
                        $xml->writeElement($key, "$itemValue");
                    }
                }
            } else if (\is_array($value)) { //associative array
                $xml->startElement($key);
                $value = $this->writeAttr($xml, $value);
                $this->writeEl($xml, $value);
                $xml->endElement();
            } else { //scalar
                $value = $this->writeAttr($xml, $value);
                $xml->writeElement($key, "$value");
            }
        }
    }
942122
protected static function saveXml( $fileName, $data )
	{
		$root	= new XML_DOM_Node( "configuration" );
		foreach( $data as $sectionName => $sectionData )
		{
			$sectionNode	= new XML_DOM_Node( "section" );
			$sectionNode->setAttribute( 'name', $sectionName );			
			foreach( $sectionData as $pair )
			{
				$comment	= isset( $pair['comment'] ) ? $pair['comment'] : NULL;
				$valueNode	= new XML_DOM_Node( "value", $pair['value'] );
				$valueNode->setAttribute( 'type', $pair['type'] );
				$valueNode->setAttribute( 'name', $pair['key'] );
				if( isset( $pair['comment'] ) )
					$valueNode->setAttribute( 'comment', $comment );
				$sectionNode->addChild( $valueNode );
			}
			$root->addChild( $sectionNode );
		}
		return XML_DOM_FileWriter::save( $fileName, $root );
	}
993362
public function writeInnerXml(\XMLWriter $xmlWriter)
    {
        Validate::notNull($xmlWriter, 'xmlWriter');
        if (!is_null($this->attributes)) {
            if (is_array($this->attributes)) {
                foreach ($this->attributes as $attributeName => $attributeValue) {
                    $xmlWriter->writeAttribute($attributeName, $attributeValue);
                }
            }
        }

        if (!is_null($this->author)) {
            Validate::isArray($this->author, Resources::AUTHOR);
            $this->writeArrayItem($xmlWriter, $this->author, Resources::AUTHOR);
        }

        if (!is_null($this->category)) {
            Validate::isArray($this->category, Resources::CATEGORY);
            $this->writeArrayItem(
                $xmlWriter,
                $this->category,
                Resources::CATEGORY
            );
        }

        if (!is_null($this->contributor)) {
            Validate::isArray($this->contributor, Resources::CONTRIBUTOR);
            $this->writeArrayItem(
                $xmlWriter,
                $this->contributor,
                Resources::CONTRIBUTOR
            );
        }

        if (!is_null($this->generator)) {
            $this->generator->writeXml($xmlWriter);
        }

        if (!is_null($this->icon)) {
            $xmlWriter->writeElementNS(
                'atom',
                'icon',
                Resources::ATOM_NAMESPACE,
                $this->icon
            );
        }

        $this->writeOptionalElementNS(
            $xmlWriter,
            'atom',
            'logo',
            Resources::ATOM_NAMESPACE,
            $this->logo
        );

        $this->writeOptionalElementNS(
            $xmlWriter,
            'atom',
            'id',
            Resources::ATOM_NAMESPACE,
            $this->id
        );

        if (!is_null($this->link)) {
            Validate::isArray($this->link, Resources::LINK);
            $this->writeArrayItem(
                $xmlWriter,
                $this->link,
                Resources::LINK
            );
        }

        $this->writeOptionalElementNS(
            $xmlWriter,
            'atom',
            'rights',
            Resources::ATOM_NAMESPACE,
            $this->rights
        );

        $this->writeOptionalElementNS(
            $xmlWriter,
            'atom',
            'subtitle',
            Resources::ATOM_NAMESPACE,
            $this->subtitle
        );

        $this->writeOptionalElementNS(
            $xmlWriter,
            'atom',
            'title',
            Resources::ATOM_NAMESPACE,
            $this->title
        );

        if (!is_null($this->updated)) {
            $xmlWriter->writeElementNS(
                'atom',
                'updated',
                Resources::ATOM_NAMESPACE,
                $this->updated->format(\DateTime::ATOM)
            );
        }
    }
309207
@Override
    public void xmlWriteOn(FormattedWriter writer) throws IOException
    {
        writer.startTag(XML_MESSAGE_STORE);
        writer.indent();
        synchronized (_startLock)
        {
            if (_state == MessageStoreState.STATE_STARTED)
            {
                _rootMembership.xmlWriteItemStreamsOn(writer);
            }
            else
            {
                writer.newLine();
                writer.write(XML_CANNOT_BE_WRITTEN);
            }
        }

        if (null != _itemStorageManager)
        {
            _itemStorageManager.xmlWriteOn(writer);
        }

        if (null != _membershipMap)
        {
            _membershipMap.xmlWriteOn(writer);
        }

        if (null != _persistentMessageStore)
        {
            _persistentMessageStore.xmlWriteOn(writer);
        }

        if (null != _expirer)
        {
            _expirer.xmlWriteOn(writer);
        }

        if (null != _cacheLoader)
        {
            _cacheLoader.xmlWriteOn(writer);
        }

        if (null != _deliveryDelayManager) {
            _deliveryDelayManager.xmlWriteOn(writer);
        }
        writer.outdent();
        writer.newLine();
        writer.endTag(XML_MESSAGE_STORE);
    }
606469
protected void xmlWriteChildrenOn(FormattedWriter writer) throws IOException 
    {
        super.xmlWriteChildrenOn(writer);
        if (null != _items)
        {
            _items.xmlWriteChildrenOn(writer, XML_ITEMS);
        }
        if (null != _itemStreams)
        {
            _itemStreams.xmlWriteOn(writer, XML_ITEM_STREAMS);
        }
        if (null != _referenceStreams)
        {
            _referenceStreams.xmlWriteOn(writer, XML_REFERENCE_STREAMS);
        }
    }
279810
@Override
    public void writeXML(XMLOutput xmlOutput) throws IOException {
        xmlOutput.openTag(ELEMENT_NAME, new XMLAttributeList().addAttribute("class", className));
        for (Iterator<String> i = featureIterator(); i.hasNext();) {
            String feature = i.next();
            xmlOutput.openCloseTag(FEATURE_ELEMENT_NAME, new XMLAttributeList().addAttribute("value", feature));
        }
        xmlOutput.closeTag(ELEMENT_NAME);
    }
80521
public static function buildXml(&$xml, $array) {
		if (is_array($array)) {
			foreach ($array as $key => $value) {
				// XML_NONE
				if (!is_array($value)) {
					$xml->addChild($key, $value);
					continue;
				}

				// Multiple nodes of the same name
				if (isset($value[0])) {
					foreach ($value as $kValue) {
						if (is_array($kValue)) {
							self::buildXml($xml, array($key => $kValue));
						} else {
							$xml->addChild($key, $kValue);
						}
					}

				// XML_GROUP
				} else if (isset($value['attributes'])) {
					if (is_array($value['value'])) {
						$node = $xml->addChild($key);
						self::buildXml($node, $value['value']);
					} else {
						$node = $xml->addChild($key, $value['value']);
					}

					if (!empty($value['attributes'])) {
						foreach ($value['attributes'] as $aKey => $aValue) {
							$node->addAttribute($aKey, $aValue);
						}
					}

				// XML_MERGE
				} else if (isset($value['value'])) {
					$node = $xml->addChild($key, $value['value']);
					unset($value['value']);

					if (!empty($value)) {
						foreach ($value as $aKey => $aValue) {
							if (is_array($aValue)) {
								self::buildXml($node, array($aKey => $aValue));
							} else {
								$node->addAttribute($aKey, $aValue);
							}
						}
					}

				// XML_OVERWRITE
				} else {
					$node = $xml->addChild($key);

					if (!empty($value)) {
						foreach ($value as $aKey => $aValue) {
							if (is_array($aValue)) {
								self::buildXml($node, array($aKey => $aValue));
							} else {
								$node->addChild($aKey, $aValue);
							}
						}
					}
				}
			}
		}

		return $xml;
	}
555745
public function xml2array(): void
    {
        $this->xml2json();
        $this->arrayData = json_decode($this->jsonData, TRUE);
    }
686084
public function xmlSerialize(Xml\Writer $writer)
    {
        $components = [];
        $properties = [];

        foreach ($this->children as $childGroup) {
            foreach ($childGroup as $child) {
                if ($child instanceof self) {
                    $components[] = $child;
                } else {
                    $properties[] = $child;
                }
            }
        }

        $writer->startElement(strtolower($this->name));

        if (!empty($properties)) {
            $writer->startElement('properties');

            foreach ($properties as $property) {
                $property->xmlSerialize($writer);
            }

            $writer->endElement();
        }

        if (!empty($components)) {
            $writer->startElement('components');

            foreach ($components as $component) {
                $component->xmlSerialize($writer);
            }

            $writer->endElement();
        }

        $writer->endElement();
    }
1264327
public void xmlWriteOn(FormattedWriter writer) throws IOException
  {
    if(durablePseudoDestID != null)
    {
      writer.newLine();
      writer.taggedValue("durablePseudoDestID", durablePseudoDestID);
    }
    if(durableSubName != null)
    {
      writer.newLine();
      writer.taggedValue("durableSubName", durableSubName);
    }
  }
827464
private function writeXmlFiles()
    {
        foreach ($this->entityDefinitions as $key => $definition) {
            $definition->writeXml($this->dataDirectory . "/entities/{$definition->name}.xml");
        }
    }
1152715
private static function array_to_xml($data = array(), &$xml_data) {
	foreach($data as $key => $value) {

	    if(is_array($value) or (is_object($value))) {
		if(!is_numeric($key)){
		    $subnode = $xml_data->addChild("$key");
		    self::array_to_xml($value, $subnode);
		}
		else{
		    $subnode = $xml_data->addChild("element");
		    self::array_to_xml($value, $subnode);
		}
	    }
	    else {
		if (is_bool($value)) {$value = $value ? "true" : "false";}
		$xml_data->addChild("$key","$value");
	    }
	}
    }
114436
public function xmlSerialize(Xml\Writer $writer)
    {
        $propertiesByGroup = [];

        foreach ($this->children() as $property) {
            $group = $property->group;

            if (!isset($propertiesByGroup[$group])) {
                $propertiesByGroup[$group] = [];
            }

            $propertiesByGroup[$group][] = $property;
        }

        $writer->startElement(strtolower($this->name));

        foreach ($propertiesByGroup as $group => $properties) {
            if (!empty($group)) {
                $writer->startElement('group');
                $writer->writeAttribute('name', strtolower($group));
            }

            foreach ($properties as $property) {
                switch ($property->name) {
                    case 'VERSION':
                        break;

                    case 'XML':
                        $value = $property->getParts();
                        $fragment = new Xml\Element\XmlFragment($value[0]);
                        $writer->write($fragment);
                        break;

                    default:
                        $property->xmlSerialize($writer);
                        break;
                }
            }

            if (!empty($group)) {
                $writer->endElement();
            }
        }

        $writer->endElement();
    }
1241142
public static void writeAttributes(XMLStreamWriter xmlStreamWriter, HierarchicalProperty property)
      throws XMLStreamException
   {
      Map<String, String> attributes = property.getAttributes();
      Iterator<String> keyIter = attributes.keySet().iterator();
      while (keyIter.hasNext())
      {
         String attrName = keyIter.next();
         String attrValue = attributes.get(attrName);
         xmlStreamWriter.writeAttribute(attrName, attrValue);
      }
   }
105884
protected function fillXml(\SimpleXMLElement $element, $data)
    {
        foreach ($data as $key => $value) {
            if (is_array($value) || is_object($value)) {
                if (!is_numeric($key)) {
                    $child = $element->addChild($key);
                } else {
                    $child = $element;
                }
                
                $this->fillXml($child, $value);
            } else {
                $element->addChild($key, $value);
            }
        }
    }
1285708
protected function xmlSerialize($data, $xml = null)
    {
        if ( !$xml instanceof SimpleXMLElement )
        {
            $xml = new SimpleXMLElement('<'. $this->requestName .' xmlns="'. $this->namespace .'" />');
        }

        foreach ($data as $key => $value)
        {
            if ( !isset($value) )
            {
                continue;
            }

            if ( is_array($value) )
            {
                $node = $xml->addChild($key);
                $this->xmlSerialize($value, $node);
            }
            else
            {
                $xml->addChild($key, $value);
            }
        }

        return $xml->asXML();
    }
279947
private function arrayToXml(array &$data, SimpleXMLElement $xmlData)
    {
        foreach ($data as $key => $value) {
            $key = ltrim($key, '_');

            if (\is_array($value)) {
                if (\is_numeric($key)) {
                    $key = 'resource';
                }

                if (false === empty($value[JsonTransformer::LINKS_HREF])) {
                    $subnode = $xmlData->addChild('link');
                    $subnode->addAttribute('rel', $key);

                    foreach ($this->linkKeys as $linkKey) {
                        if (!empty($value[$linkKey])) {
                            $subnode->addAttribute($linkKey, $value[$linkKey]);
                        }
                    }
                } else {
                    if (!empty($value[JsonTransformer::LINKS_KEY][JsonTransformer::LINK_SELF][JsonTransformer::LINKS_HREF])) {
                        $subnode = $xmlData->addChild('resource');
                        $subnode->addAttribute(
                            JsonTransformer::LINKS_HREF,
                            $value[JsonTransformer::LINKS_KEY][JsonTransformer::LINK_SELF][JsonTransformer::LINKS_HREF]
                        );

                        if ($key !== 'resource') {
                            $subnode->addAttribute('rel', $key);
                        }
                    } else {
                        $subnode = $xmlData->addChild($key);
                    }
                }

                $this->arrayToXml($value, $subnode);
            } else {
                if ($key !== JsonTransformer::LINKS_HREF) {
                    if ($value === true || $value === false) {
                        $value = ($value) ? 'true' : 'false';
                    }

                    $xmlData->addChild("$key", '<![CDATA['.html_entity_decode($value).']]>');
                }
            }
        }
    }