You are here

protected function AbstractSolrEntity::buildXmlFromArray in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Entity/AbstractSolrEntity.php \Drupal\search_api_solr\Entity\AbstractSolrEntity::buildXmlFromArray()

Formats a given array to an XML string.

5 calls to AbstractSolrEntity::buildXmlFromArray()
AbstractSolrEntity::getSolrConfigsAsXml in src/Entity/AbstractSolrEntity.php
Gets the Solr Field Type specific additions to solrconfig.xml as XML.
SolrCache::getAsXml in src/Entity/SolrCache.php
Gets the Solr Entity definition as XML fragment.
SolrFieldType::getSubFieldTypeAsXml in src/Entity/SolrFieldType.php
Serializes a filed type as XML fragment as required by Solr.
SolrRequestDispatcher::getAsXml in src/Entity/SolrRequestDispatcher.php
Gets the Solr Entity definition as XML fragment.
SolrRequestHandler::getAsXml in src/Entity/SolrRequestHandler.php
Gets the Solr Entity definition as XML fragment.

File

src/Entity/AbstractSolrEntity.php, line 68

Class

AbstractSolrEntity
Defines the abstract base class for Solr config entities.

Namespace

Drupal\search_api_solr\Entity

Code

protected function buildXmlFromArray($root_element_name, array $attributes) {

  /** @noinspection PhpComposerExtensionStubsInspection */
  $root = new \SimpleXMLElement('<' . $root_element_name . '/>');
  self::buildXmlFromArrayRecursive($root, $attributes);

  // Create formatted string.

  /** @noinspection PhpComposerExtensionStubsInspection */
  $dom = dom_import_simplexml($root)->ownerDocument;
  $dom->formatOutput = TRUE;
  $formatted_xml_string = $dom
    ->saveXML();

  // Remove the XML declaration before returning the XML fragment.
  return preg_replace('/<\\?.*?\\?>\\s*\\n?/', '', $formatted_xml_string);
}