本文整理汇总了PHP中DomDocument::loadXML方法的典型用法代码示例。如果您正苦于以下问题:PHP DomDocument::loadXML方法的具体用法?PHP DomDocument::loadXML怎么用?PHP DomDocument::loadXML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomDocument
的用法示例。
在下文中一共展示了DomDocument::loadXML方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param string|null $data
* @param bool $formatOutput
*
* @throws \Exception
*/
public function __construct($data = null, $formatOutput = false)
{
$this->dom = new \DomDocument('1.0', 'UTF-8');
$this->dom->preserveWhiteSpace = false;
$this->dom->formatOutput = $formatOutput;
$this->dom->substituteEntities = false;
if (!$data) {
$data = '<x:xmpmeta xmlns:x="adobe:ns:meta/" />';
}
// load xml
$this->dom->loadXML($data);
$this->dom->encoding = 'UTF-8';
if ('x:xmpmeta' !== $this->dom->documentElement->nodeName) {
throw new \RuntimeException('Root node must be of type x:xmpmeta.');
}
// set up xpath
$this->xpath = new \DOMXPath($this->dom);
foreach ($this->namespaces as $prefix => $url) {
$this->xpath->registerNamespace($prefix, $url);
}
// try and find an rdf:about attribute, and set it as the default if found
$about = $this->xpath->query('//rdf:Description/@rdf:about')->item(0);
if ($about) {
$this->about = $about->nodeValue;
}
}
示例2: __construct
/**
* Construct the response object.
*
* @param OneLogin_Saml_Settings $settings Settings containing the necessary X.509 certificate to decode the XML.
* @param string $assertion A UUEncoded SAML assertion from the IdP.
*/
public function __construct(OneLogin_Saml_Settings $settings, $assertion)
{
$this->_settings = $settings;
$this->assertion = base64_decode($assertion);
$this->document = new DOMDocument();
$this->document->loadXML($this->assertion);
}
示例3: __construct
/**
* Construct the response object.
*
* @param string $saml_response A UUEncoded SAML response from the IdP.
*/
public function __construct($saml_response, $settings = null)
{
if ($settings == null) {
$settings = Maestrano::sso()->getSamlSettings();
}
$this->_settings = $settings;
$this->assertion = base64_decode($saml_response);
$this->document = new DOMDocument();
$this->document->loadXML($this->assertion);
}
示例4: evaluate
/**
* @param {@link ViewElement} $viewElement
* @param integer $arity
* @param array $arguments
*/
public function evaluate(ViewElementTag $viewElement, $arity, $arguments)
{
$xmlString = $arguments[0];
$xml = new \DomDocument();
$successParse = @$xml->loadXML($xmlString, LIBXML_NOENT);
if (!$successParse) {
$explicitRoot = $arity >= 2 ? $arguments[1] : 'xml';
$xmlString = '<' . $explicitRoot . '>' . $arguments[0] . '</' . $explicitRoot . '>';
// This time we let a warning be fired in case of invalid xml.
$xml->loadXML($xmlString, LIBXML_NOENT);
}
$xpath = new \DOMXPath($xml);
return $xpath;
}
示例5: DomDocument
function __doRequest($request, $location, $action, $version)
{
$dom = new DomDocument('1.0', 'UTF-8');
$dom->preserveWhiteSpace = false;
$dom->loadXML($request);
$hdr = $dom->createElement('soapenv:Header');
$secNode = $dom->createElement("wsse:Security");
$secNode->setAttribute("soapenv:mustUnderstand", "1");
$secNode->setAttribute("xmlns:wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
$usernameTokenNode = $dom->createElement("wsse:UsernameToken");
$usernameTokenNode->setAttribute("wsu:Id", "UsernameToken-1");
$usernameTokenNode->setAttribute("xmlns:wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
$usrNode = $dom->createElement("wsse:Username");
$usrNode->appendChild($dom->createTextNode(WS_USER));
$pwdNode = $dom->createElement("wsse:Password");
$pwdNode->setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
$pwdNode->appendchild($dom->createTextnode(WS_PWD));
$usernameTokenNode->appendChild($usrNode);
$usernameTokenNode->appendChild($pwdNode);
$secNode->appendChild($usernameTokenNode);
$hdr->appendChild($secNode);
$dom->documentElement->insertBefore($hdr, $dom->documentElement->firstChild);
$request = $dom->saveXML();
$request = str_replace("SOAP-ENV", "soapenv", $request);
$request = str_replace("ns1", "cgt", $request);
$request = str_replace('<?xml version="1.0" encoding="UTF-8"?>', '', $request);
// echo "Este es el nuevo XML: " . print_r($request, true);
return parent::__doRequest($request, $location, $action, $version);
}
示例6: getAttachment
function getAttachment($inMessage)
{
$cid2stringMap = $inMessage->attachments;
$cid2contentMap = $inMessage->cid2contentType;
$imageName;
$arraysize = count($cid2contentMap);
if ($arraysize == 0) {
$dom = new DomDocument();
$dom->loadXML($inMessage->str);
$images = $dom->documentElement->getElementsByTagName('image');
$image = $images->item(0);
if (stristr(PHP_OS, 'WIN')) {
file_put_contents("base64image.txt", $image->nodeValue);
$str = base64_decode($image->nodeValue);
file_put_contents("decoded_image.jpg", $str);
} else {
file_put_contents("/tmp/base64image.txt", $image->nodeValue);
$str = base64_decode($image->nodeValue);
file_put_contents("/tmp/decoded_image.jpg", $str);
}
}
$responsePayload = <<<XML
<ns1:response xmlns:ns1="http://php.axis2.org/samples/mtom">Image Saved</ns1:response>
XML;
$returnMessage = new WSMessage($responsePayload);
return $returnMessage;
}
示例7: getXMLSing
function getXMLSing($xmlHon,$priv_key){
//Carga Certificado
$xml = new DomDocument();
$xml->loadXML($xmlHon);
//Carga prosedimiento de proceso de cadena original
$xsl = new DomDocument;
$xsl->load("ostring.xsl");
$proc = new xsltprocessor();
$proc->importStyleSheet($xsl);
$original =$proc->transformToXML($xml);
//firma la cadena original
//$fp = $cert[0]['certificates']['key'];
//$priv_key = $f['key'];
//die($f['key']);
//fclose($fp);
$pkeyid = openssl_get_privatekey($priv_key);
openssl_sign($original, $signature, $pkeyid,OPENSSL_ALGO_MD5);
openssl_free_key($pkeyid);
//coloca el sello en xml
$esqueletonew=$xmlHon;
$esqueletonew=str_replace("#1#",base64_encode($signature),$esqueletonew);
$xmlReturn[1]=$esqueletonew;
$xmlReturn[2]=$original;
$xmlReturn[3]=base64_encode($signature);
return $xmlReturn;
}
示例8: parse_session_status_XML
function parse_session_status_XML($xml_)
{
if (!$xml_ || strlen($xml_) == 0) {
return false;
}
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($xml_);
if (!$buf) {
return false;
}
if (!$dom->hasChildNodes()) {
return false;
}
$node = $dom->getElementsByTagname('session')->item(0);
if (is_null($node)) {
return false;
}
if (!$node->hasAttribute('id')) {
return false;
}
if (!$node->hasAttribute('status')) {
return false;
}
$ret = array('id' => $node->getAttribute('id'), 'server' => $_SERVER['REMOTE_ADDR'], 'status' => $node->getAttribute('status'), 'reason' => NULL, 'role' => NULL);
if ($node->hasAttribute('reason')) {
$ret['reason'] = $node->getAttribute('reason');
}
if ($node->hasAttribute('role')) {
$ret['role'] = $node->getAttribute('role');
}
return $ret;
}
示例9: DomDocument
function xslt_process($xsltproc, $xml_arg, $xsl_arg, $xslcontainer = null, $args = null, $params = null)
{
// Start with preparing the arguments
$xml_arg = str_replace('arg:', '', $xml_arg);
$xsl_arg = str_replace('arg:', '', $xsl_arg);
// Create instances of the DomDocument class
$xml = new DomDocument();
$xsl = new DomDocument();
$phpversion = explode('.', PHP_VERSION);
$phpversionid = $phpversion[0] * 10000 + $phpversion[1] * 100 + $phpversion[2];
// Load the xml document and the xsl template
if ($phpversionid >= 50302 && LIBXML_VERSION >= 20700) {
$xmlOptions = LIBXML_PARSEHUGE;
} else {
$xmlOptions = 0;
}
$xml->loadXML($args[$xml_arg], $xmlOptions);
$xsl->loadXML(file_get_contents($xsl_arg), $xmlOptions);
// Load the xsl template
$xsltproc->importStyleSheet($xsl);
// Set parameters when defined
if ($params) {
foreach ($params as $param => $value) {
$xsltproc->setParameter("", $param, $value);
}
}
// Start the transformation
$processed = $xsltproc->transformToXML($xml);
// Put the result in a file when specified
if ($xslcontainer) {
return @file_put_contents($xslcontainer, $processed);
} else {
return $processed;
}
}
示例10: login
/**
* Logs into Windows Live
*
* @return true on success else error
*/
public function login()
{
// Register device
$register = $this->registerDevice();
// Get binary DA token
$response = $this->getBinaryDAToken($this->messageid, $this->deviceUserName, $this->devicePassword);
$responsedom = new DomDocument();
$responsedom->loadXML($response);
$cipherValues = $responsedom->getElementsbyTagName("CipherValue");
$this->cipherValue = $cipherValues->item(0)->textContent;
if (!empty($this->cipherValue)) {
// Get security tokens
$response = $this->getSecurityTokens($this->cipherValue);
$responsedom = new DomDocument();
$responsedom->loadXML($response);
$cipherValues = $responsedom->getElementsbyTagName("CipherValue");
$this->securityToken0 = $cipherValues->item(0)->textContent;
$this->securityToken1 = $cipherValues->item(1)->textContent;
$this->keyIdentifier = $responsedom->getElementsbyTagName("KeyIdentifier")->item(0)->textContent;
if (empty($this->keyIdentifier) || empty($this->securityToken0) || empty($this->securityToken1)) {
$this->_error = "Failed to get security tokens.";
} else {
return true;
}
} else {
$this->_error = "Failed to get binary DA token.";
}
}
示例11: isset
function __construct($url, $response, $browser)
{
$this->url = $url;
$this->html = $response;
$this->parseResponse($response);
$this->is_xml = isset($this->headers['Content-Type']) && preg_match('/\\bxml\\b/i', $this->headers['Content-Type']) ? true : false;
$this->browser = $browser;
$this->dom = new DOMDocument();
if ($this->is_xml) {
@$this->dom->loadXML($this->html);
} else {
@$this->dom->loadHTML($this->html);
}
$this->xpath = new DOMXPath($this->dom);
$this->title = ($node = $this->xpath->query('//title')->item(0)) ? $node->nodeValue : '';
$this->forms = array();
foreach ($this->xpath->query('//form') as $form) {
$this->_forms[] = new PGForm($form, $this);
}
if ($browser->convertUrls) {
$this->convertUrls();
}
$this->setParser($this->html, $this->is_xml);
if (function_exists('gc_collect_cycles')) {
gc_collect_cycles();
}
}
示例12: create_from_server_report
public static function create_from_server_report($server_id_, $xml_input_)
{
$server = Abstract_Server::load($server_id_);
if ($server === false) {
return;
}
$external_name = $server->getExternalName();
$dom = new DomDocument('1.0', 'utf-8');
$dom->loadXML($xml_input_);
if (!is_object($dom)) {
return null;
}
$node = $dom->getElementsByTagName('cpu');
if ($node->length > 0) {
$cpu = round($node->item(0)->getAttribute('load'), 2);
} else {
$cpu = -1;
}
$node = $dom->getElementsByTagName('ram');
if ($node->length > 0) {
$total = (double) $server->ram_total;
$used = (double) $node->item(0)->getAttribute('used');
if ($total > 0) {
$ram = round($used / $total * 100, 2);
} else {
$ram = 0;
}
} else {
$ram = -1;
}
$sessions = $dom->getElementsByTagName('session');
$apps_link = application_desktops_to_ids();
$sessions_infos = array();
$applications_infos = array();
/* the interesting <session> nodes of the xml are like:
<session id="ID" mode="MODE" status="STATUS" user="LOGIN">
<instance application="APP_ID" id="ApS_ID"/>
</session>
*/
foreach ($sessions as $session) {
$sessid = $session->getAttribute('id');
$sessions_infos[$sessid] = $session->getAttribute('user');
foreach ($session->childNodes as $instance_node) {
if ($instance_node->tagName == 'instance') {
$desktop = $instance_node->getAttribute('application');
if (!array_key_exists($desktop, $apps_link)) {
continue;
}
$id = $apps_link[$desktop];
if (!array_key_exists($id, $applications_infos)) {
$applications_infos[$id] = array();
}
$applications_infos[$id][] = $sessid;
}
}
}
$data = self::infos2Xml($sessions_infos, $applications_infos);
$report = new self(time(), $server_id_, $server->fqdn, $external_name, $cpu, $ram, $data);
return $report;
}
示例13: header
function upcoming_events()
{
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
$xml = new DomDocument();
$xml->loadXML($this->get_upcoming_events());
echo $xml->saveXML();
}
示例14: format
function format($xml)
{
$dom = new DomDocument();
$dom->loadXML($xml);
$dom->formatOutput = true;
return $dom->saveXML();
}
示例15: testUpdateOnLicenceChange
public function testUpdateOnLicenceChange()
{
$document = $this->createTestDocument();
$document->store();
$documentCacheTable = new Opus_Db_DocumentXmlCache();
$docXmlCache = $documentCacheTable->find($document->getId(), '1')->current()->xml_data;
$domDoc = new DomDocument();
$domDoc->loadXML($docXmlCache);
$licences = $domDoc->getElementsByTagName('Licence');
$this->assertTrue($licences->length == 0, 'Expected no Licence element in dom.');
$licence = new Opus_Licence();
$licence->setNameLong('TestLicence');
$licence->setLinkLicence('http://example.org/licence');
$licenceId = $licence->store();
$document->setServerState('published');
$document->setLicence($licence);
$docId = $document->store();
$licence = new Opus_Licence($licenceId);
$licence->setNameLong('TestLicenceAltered');
$licence->store();
$docXmlCacheResult = $documentCacheTable->find($document->getId(), '1');
$this->assertTrue($docXmlCacheResult->count() == 0, 'Expected empty document xml cache');
$this->executeScript('cron-update-document-cache.php');
$docXmlCacheAfter = $documentCacheTable->find($docId, '1')->current()->xml_data;
$domDocAfter = new DomDocument();
$domDocAfter->loadXML($docXmlCacheAfter);
$licencesAfter = $domDocAfter->getElementsByTagName('Licence');
$this->assertTrue($licencesAfter->length == 1, 'Expected one Licence element in dom.');
$licences = $document->getLicence();
$licences[0]->delete();
}