Jackalope\ImportExport\ImportExport::importXML PHP Method

importXML() public static method

Import the xml document from the stream into the repository
See also: SessionInterface::importXML
public static importXML ( PHPCR\NodeInterface $parentNode, PHPCR\NamespaceRegistryInterface $ns, string $uri, integer $uuidBehavior )
$parentNode PHPCR\NodeInterface as in importXML
$ns PHPCR\NamespaceRegistryInterface as in importXML
$uri string as in importXML
$uuidBehavior integer as in importXML
    public static function importXML(NodeInterface $parentNode, NamespaceRegistryInterface $ns, $uri, $uuidBehavior)
    {
        $use_errors = libxml_use_internal_errors(true);
        libxml_clear_errors();
        if (!file_exists($uri)) {
            throw new \RuntimeException("File {$uri} does not exist or is not readable");
        }
        $xml = new FilteredXMLReader();
        $options = 0;
        if (LIBXML_VERSION >= 20700) {
            $options = LIBXML_PARSEHUGE;
        }
        $xml->open($uri, null, $options);
        if (libxml_get_errors()) {
            libxml_use_internal_errors($use_errors);
            throw new InvalidSerializedDataException("Invalid xml file {$uri}");
        }
        $xml->read();
        try {
            if ('node' === $xml->localName && NamespaceRegistryInterface::NAMESPACE_SV === $xml->namespaceURI) {
                // TODO: validate with DTD?
                self::importSystemView($parentNode, $ns, $xml, $uuidBehavior);
            } else {
                self::importDocumentView($parentNode, $ns, $xml, $uuidBehavior);
            }
        } catch (\Exception $e) {
            // restore libxml setting
            libxml_use_internal_errors($use_errors);
            // and rethrow exception to not hide it
            throw $e;
        }
        libxml_use_internal_errors($use_errors);
    }

Usage Example

Example #1
0
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function importXML($parentAbsPath, $uri, $uuidBehavior)
 {
     ImportExport::importXML($this->getNode($parentAbsPath), $this->workspace->getNamespaceRegistry(), $uri, $uuidBehavior);
 }