当前位置: 首页>>代码示例>>PHP>>正文


PHP DOMDocument::loadXML方法代码示例

本文整理汇总了PHP中DOMDocument::loadXML方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::loadXML方法的具体用法?PHP DOMDocument::loadXML怎么用?PHP DOMDocument::loadXML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DOMDocument的用法示例。


在下文中一共展示了DOMDocument::loadXML方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadString

 /**
  * Function to load template data from a string instead of a file. e.g. the template is parsed first by php
  * @param unknown_type $str
  */
 public function loadString($str)
 {
     $this->_template_data = new DOMDocument();
     $this->_template_data->preserveWhiteSpace = false;
     $this->_template_data->loadXML($str);
     $this->createRestorePoint();
 }
开发者ID:nadeemshafique,项目名称:entrada-1x,代码行数:11,代码来源:Template.class.php

示例2: ValueToID

 private function ValueToID($key, $value)
 {
     if (is_int($value)) {
         return $value;
     }
     $data = null;
     $x = new DOMDocument();
     $v = null;
     switch (strtolower($key)) {
         case "vo":
             $data = $this->VOs();
             $x->loadXML($data);
             $v = $x->getElementsByTagName("vo");
             break;
         case "country":
             $data = $this->Regional();
             $x->loadXML($data);
             $v = $x->getElementsByTagName("country");
             break;
         default:
             return $value;
             break;
     }
     $c = $v->length;
     for ($i = 0; $i < $v->length; $i++) {
         $vv = strtolower($key) === 'vo' ? $v->item($i)->getAttribute("name") : $v->item($i)->nodeValue;
         if (strtolower($vv) === strtolower($value)) {
             return $v->item($i)->getAttribute("id");
         }
     }
     return $value;
 }
开发者ID:IASA-GR,项目名称:appdb-core,代码行数:32,代码来源:AppDBAPI.php

示例3: testMarshalling

 public function testMarshalling()
 {
     $indexedEndpointType = new SAML2_XML_md_IndexedEndpointType();
     $indexedEndpointType->Binding = 'TestBinding';
     $indexedEndpointType->Location = 'TestLocation';
     $indexedEndpointType->index = 42;
     $indexedEndpointType->isDefault = FALSE;
     $document = new DOMDocument();
     $document->loadXML('<root />');
     $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test');
     $indexedEndpointElements = SAML2_Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test');
     $this->assertCount(1, $indexedEndpointElements);
     $indexedEndpointElement = $indexedEndpointElements[0];
     $this->assertEquals('TestBinding', $indexedEndpointElement->getAttribute('Binding'));
     $this->assertEquals('TestLocation', $indexedEndpointElement->getAttribute('Location'));
     $this->assertEquals('42', $indexedEndpointElement->getAttribute('index'));
     $this->assertEquals('false', $indexedEndpointElement->getAttribute('isDefault'));
     $indexedEndpointType->isDefault = TRUE;
     $document->loadXML('<root />');
     $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test');
     $indexedEndpointTypeElement = SAML2_Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test');
     $this->assertCount(1, $indexedEndpointTypeElement);
     $this->assertEquals('true', $indexedEndpointTypeElement[0]->getAttribute('isDefault'));
     $indexedEndpointType->isDefault = NULL;
     $document->loadXML('<root />');
     $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test');
     $indexedEndpointTypeElement = SAML2_Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test');
     $this->assertCount(1, $indexedEndpointTypeElement);
     $this->assertTrue(!$indexedEndpointTypeElement[0]->hasAttribute('isDefault'));
 }
开发者ID:danielkjfrog,项目名称:docker,代码行数:30,代码来源:IndexedEndpointTypeTest.php

示例4: __toString

 public function __toString()
 {
     $string = '';
     $dom = new DOMDocument();
     $dom->preserveWhiteSpace = FALSE;
     $dom->formatOutput = TRUE;
     $string .= '<pre>';
     $string .= 'Exception: ' . $this->getMessage() . '<br><br><br><br>';
     $string .= 'If you think there is a bug in SimpleCalDAV, please report the following information on github or send it at palm.michael@gmx.de.<br><br><br>';
     $string .= '<br>For debugging purposes:<br>';
     $string .= '<br>last request:<br><br>';
     $string .= $this->requestHeader;
     if (!empty($this->requestBody)) {
         if (!preg_match('#^Content-type:.*?text/calendar.*?$#', $this->requestHeader, $matches)) {
             $dom->loadXML($this->requestBody);
             $string .= htmlentities($dom->saveXml());
         } else {
             $string .= htmlentities($this->requestBody) . '<br><br>';
         }
     }
     $string .= '<br>last response:<br><br>';
     $string .= $this->responseHeader;
     if (!empty($this->responseBody)) {
         if (!preg_match('#^Content-type:.*?text/calendar.*?$#', $this->responseHeader, $matches)) {
             $dom->loadXML($this->responseBody);
             $string .= htmlentities($dom->saveXml());
         } else {
             $string .= htmlentities($this->responseBody);
         }
     }
     $string .= '<br><br>';
     $string .= 'Trace:<br><br>' . $this->getTraceAsString();
     $string .= '</pre>';
     return $string;
 }
开发者ID:macrotux,项目名称:simplecaldav,代码行数:35,代码来源:CalDAVException.php

示例5: __construct

    public function __construct($name = null, array $data = array(), $dataName = '')
    {
        $this->createdDOMValue = new DOMDocument();
        $this->createdDOMValue->loadXML(<<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0">
    <para><link xlink:href="ezlocation://58" xlink:show="none">link1</link></para>
    <para><link xlink:href="ezcontent://54" xlink:show="none">link2</link> <ezembedinline xlink:href="ezlocation://60" view="embed" xml:id="embed-id-1" ezxhtml:class="embed-class" ezxhtml:align="left"></ezembedinline></para>
</section>
EOT
);
        $this->updatedDOMValue = new DOMDocument();
        $this->updatedDOMValue->loadXML(<<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0">
    <para><link xlink:href="ezlocation://60" xlink:show="none">link1</link></para>
    <para><link xlink:href="ezcontent://56" xlink:show="none">link2</link></para>
    <ezembed xlink:href="ezcontent://54" view="embed" xml:id="embed-id-1" ezxhtml:class="embed-class" ezxhtml:align="left">
      <ezconfig>
        <ezvalue key="size">medium</ezvalue>
        <ezvalue key="offset">10</ezvalue>
        <ezvalue key="limit">5</ezvalue>
      </ezconfig>
    </ezembed>
</section>
EOT
);
        parent::__construct($name, $data, $dataName);
    }
开发者ID:emodric,项目名称:ezpublish-kernel,代码行数:29,代码来源:RichTextIntegrationTest.php

示例6: build

 /**
  * Detects feed types and instantiate appropriate objects.
  *
  * Our constructor takes care of detecting feed types and instantiating
  * appropriate classes. For now we're going to treat Atom 0.3 as Atom 1.0
  * but raise a warning. I do not intend to introduce full support for 
  * Atom 0.3 as it has been deprecated, but others are welcome to.
  *
  * @param    string    $feed    XML serialization of the feed
  * @param    bool    $strict    Whether or not to validate the feed
  * @param    bool    $suppressWarnings Trigger errors for deprecated feed types?
  * @param    bool    $tidy    Whether or not to try and use the tidy library on input
  */
 function build(DOMDocument $model, $feed, $strict = false, $suppressWarnings = false, $tidy = false)
 {
     $options = 0;
     if ($suppressWarnings) {
         $options |= LIBXML_NOWARNING;
         $options |= LIBXML_NOERROR;
     }
     if (empty($feed)) {
         throw new XML_Feed_Parser_Exception('Invalid input: file is empty');
     }
     if (!$model->loadXML($feed, $options)) {
         if (extension_loaded('tidy') && $tidy) {
             $tidy = new tidy();
             $tidy->parseString($feed, array('input-xml' => true, 'output-xml' => true));
             $tidy->cleanRepair();
             if (!$model->loadXML((string) $tidy)) {
                 throw new XML_Feed_Parser_Exception('Invalid input: this is not ' . 'valid XML');
             }
         } else {
             throw new XML_Feed_Parser_Exception('Invalid input: this is not valid XML');
         }
     }
     /* detect feed type */
     $doc_element = $model->documentElement;
     $class = $this->determineClass($doc_element, $suppressWarnings);
     /* Instantiate feed object */
     $feed = new $class($model, $strict);
     $feed->setSanitizer(new XML_Feed_Parser_Unsafe_Sanitizer());
     return $feed;
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:43,代码来源:Factory.php

示例7: testUnmarshalling

    public function testUnmarshalling()
    {
        $mdNamespace = SAML2_Const::NS_MD;
        $document = new DOMDocument();
        $document->loadXML(<<<XML
<md:Test xmlns:md="{$mdNamespace}" Binding="urn:something" Location="https://whatever/" xmlns:test="urn:test" test:attr="value" />
XML
);
        $endpointType = new SAML2_XML_md_EndpointType($document->firstChild);
        $this->assertEquals(TRUE, $endpointType->hasAttributeNS('urn:test', 'attr'));
        $this->assertEquals('value', $endpointType->getAttributeNS('urn:test', 'attr'));
        $this->assertEquals(FALSE, $endpointType->hasAttributeNS('urn:test', 'invalid'));
        $this->assertEquals('', $endpointType->getAttributeNS('urn:test', 'invalid'));
        $endpointType->removeAttributeNS('urn:test', 'attr');
        $this->assertEquals(FALSE, $endpointType->hasAttributeNS('urn:test', 'attr'));
        $this->assertEquals('', $endpointType->getAttributeNS('urn:test', 'attr'));
        $endpointType->setAttributeNS('urn:test2', 'test2:attr2', 'value2');
        $this->assertEquals('value2', $endpointType->getAttributeNS('urn:test2', 'attr2'));
        $document->loadXML('<root />');
        $endpointTypeElement = $endpointType->toXML($document->firstChild, 'md:Test');
        $endpointTypeElements = SAML2_Utils::xpQuery($endpointTypeElement, '/root/saml_metadata:Test');
        $this->assertCount(1, $endpointTypeElements);
        $endpointTypeElement = $endpointTypeElements[0];
        $this->assertEquals('value2', $endpointTypeElement->getAttributeNS('urn:test2', 'attr2'));
        $this->assertEquals(FALSE, $endpointTypeElement->hasAttributeNS('urn:test', 'attr'));
    }
开发者ID:danielkjfrog,项目名称:docker,代码行数:26,代码来源:EndpointTypeTest.php

示例8: setUp

    protected function setUp()
    {
        parent::setUp();
        $this->createdDOMValue = new DOMDocument();
        $this->createdDOMValue->loadXML(<<<EOT
<?xml version="1.0" encoding="utf-8"?>
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">
<paragraph>Example</paragraph>
<paragraph><link node_id="58">link1</link></paragraph>
<paragraph><link object_id="54">link2</link></paragraph>
<paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
    <embed view="embed" size="medium" node_id="60" custom:offset="0" custom:limit="5"/>
    <embed view="embed" size="medium" object_id="56" custom:offset="0" custom:limit="5"/>
</paragraph>
</section>
EOT
);
        $this->updatedDOMValue = new DOMDocument();
        $this->updatedDOMValue->loadXML(<<<EOT
<?xml version="1.0" encoding="utf-8"?>
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">
<paragraph>Example 2</paragraph>
<paragraph><link node_id="60">link1</link></paragraph>
<paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
    <embed view="embed" size="medium" object_id="56" custom:offset="0" custom:limit="5"/>
</paragraph>
</section>
EOT
);
    }
开发者ID:CG77,项目名称:ezpublish-kernel,代码行数:30,代码来源:XmlTextIntegrationTest.php

示例9: _render

 protected function _render($bAdminMode = false)
 {
     $sContent = $this->content;
     if ($bAdminMode) {
         $oTMPDocument = new DOMDocument();
         $oTMPDocument->loadXML('<root>' . str_replace('&', '&amp;', $sContent) . '</root>');
         if ($oTMPDocument->firstChild->childNodes->length == 1 && $oTMPDocument->firstChild->childNodes->item(0)->nodeType == XML_TEXT_NODE) {
             $oTMPDocument->loadXML('<root><p>' . $sContent . '</p></root>');
         }
         foreach ($oTMPDocument->firstChild->childNodes as $oChildNode) {
             if ($oChildNode->nodeType == XML_TEXT_NODE) {
                 continue;
             }
             if ($oChildNode->nodeName == 'div') {
                 $oChildNode->parentNode->removeChild($oChildNode);
                 continue;
             }
             foreach ($this->_oNode->attributes as $oOriginalNodeAttribute) {
                 $oChildNode->setAttribute($oOriginalNodeAttribute->name, $oOriginalNodeAttribute->value);
             }
             // $oChildNode->setAttribute( 'data-brick', $this->ref );
             $oChildNode->setAttribute('data-brick-parsed', 'yes');
             DOMParser::addClassTo('posib-editable', $oChildNode);
         }
         $sContent = null;
         DOMParser::getNodeContent($oTMPDocument->firstChild, $sContent);
     }
     DOMParser::replaceNodeWithContent(str_replace('& ', '&amp; ', $this->_cleanContent($sContent)), $this->_oNode);
 }
开发者ID:posib,项目名称:posib-legacy,代码行数:29,代码来源:rich_brick.php

示例10: loadSchema

 /**
  * Load XML schema string
  * 
  * @param  string $xmlSchema
  */
 protected function loadSchema($xmlSchema)
 {
     $this->doc = new \DOMDocument();
     $this->doc->loadXML(mb_convert_encoding($xmlSchema, $this->encoding, mb_detect_encoding($xmlSchema)));
     $this->xpath = new \DOMXPath($this->doc);
     $this->xpath->registerNamespace($this->namespacePrefix, $this->xmlSchemaNamespace);
 }
开发者ID:rahmanda,项目名称:kokaku,代码行数:12,代码来源:FormSchema.php

示例11: __construct

 /**
  * @param string $xml
  *
  * @throws XMLSuggestionException
  */
 public function __construct($xml)
 {
     $this->xml = $xml;
     $this->document = new \DOMDocument();
     if (!@$this->document->loadXML($this->xml)) {
         throw new XMLSuggestionsException('Invalid XML supplied.');
     }
 }
开发者ID:wildlyinaccurate,项目名称:google-suggestqueries-api,代码行数:13,代码来源:XMLSuggestions.php

示例12: __construct

 /**
  * Constructor
  * @param string $xml XML
  */
 public function __construct($xml, XmlParserFunctions $functions)
 {
     $this->doc = new \DOMDocument();
     if (!@$this->doc->loadXML($xml) || !@($this->xp = new \DOMXPath($this->doc))) {
         throw new \RuntimeException('Error while loading the XML.');
     }
     $this->functions = $functions;
 }
开发者ID:areinert,项目名称:metador2,代码行数:12,代码来源:XmlParser.php

示例13: buildXML

 public function buildXML()
 {
     $utf8Body = utf8_encode($this->body);
     $afterJdm = explode('<code>', $utf8Body);
     $xml = explode('</code>', $afterJdm[1]);
     //echo '<textarea>' . $xml[0] . '</textarea>';
     $this->dom->loadXML(str_replace('<br>', '<br />', $xml[0]));
 }
开发者ID:Brotic66,项目名称:M2-PHPResponsive,代码行数:8,代码来源:XMLServiceBuilder.php

示例14: xslt_process

function xslt_process($xh, $xmlcontainer, $xslcontainer, $resultcontainer = null, $arguments = array(), $parameters = array())
{
    //See also: http://alexandre.alapetite.fr/doc-alex/domxml-php4-php5/
    //Based on: http://www.php.net/manual/ref.xsl.php#45415
    $xml = new DOMDocument();
    $basedir = $xh->getParameter('sablotron', 'xslt_base_dir');
    if ($basedir && ($workdir = getcwd())) {
        chdir($basedir);
    }
    if (substr($xmlcontainer, 0, 5) === 'arg:/') {
        $arg = substr($xmlcontainer, 5);
        if (isset($arguments['/' . $arg])) {
            $xml->loadXML($arguments['/' . $arg]);
        } elseif (isset($arguments[$arg])) {
            $xml->loadXML($arguments[$arg]);
        }
    } else {
        $xml->load($xmlcontainer);
    }
    $xsl = new DOMDocument();
    if (substr($xslcontainer, 0, 5) === 'arg:/') {
        $arg = substr($xslcontainer, 5);
        if (isset($arguments['/' . $arg])) {
            $xsl_ =& $arguments['/' . $arg];
        } elseif (isset($arguments[$arg])) {
            $xsl_ =& $arguments[$arg];
        } else {
            $xsl_ = '';
        }
    } else {
        $xsl_ = file_get_contents($xslcontainer);
    }
    $xsl->loadXML(str_replace('arg:/', 'arg://', $xsl_));
    $xh->importStyleSheet($xsl);
    global $xslArgs;
    $xslArgs = $arguments;
    if ($parameters != null) {
        foreach ($parameters as $param => $value) {
            $xh->setParameter('', $param, $value);
        }
    }
    $result = $xh->transformToXML($xml);
    if (isset($resultcontainer)) {
        if (substr($resultcontainer, 0, 4) === 'arg:') {
            $xslArgs[substr($resultcontainer, 4)] = $result;
        } else {
            file_put_contents($resultcontainer, $result);
        }
    }
    if ($basedir && $workdir) {
        chdir($workdir);
    }
    if (isset($resultcontainer)) {
        return true;
    } else {
        return $result;
    }
}
开发者ID:BackupTheBerlios,项目名称:wpdojoloader-svn,代码行数:58,代码来源:xslt-php4-to-php5.php

示例15: setXML

 public function setXML($xml)
 {
     assert('is_string($xml)');
     $this->dom = new DOMDocument();
     $ok = $this->dom->loadXML(str_replace("\r", "", $xml));
     if (!$ok) {
         throw new Exception('Unable to parse AuthnResponse XML.');
     }
 }
开发者ID:Stony-Brook-University,项目名称:doitsbu,代码行数:9,代码来源:AuthnResponse.php


注:本文中的DOMDocument::loadXML方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。