本文整理匯總了PHP中domDocument::loadxml方法的典型用法代碼示例。如果您正苦於以下問題:PHP domDocument::loadxml方法的具體用法?PHP domDocument::loadxml怎麽用?PHP domDocument::loadxml使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類domDocument
的用法示例。
在下文中一共展示了domDocument::loadxml方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: bench2
function bench2()
{
global $XML;
$dom = new domDocument();
$dom->loadxml($XML);
$children = $dom->getElementsByTagName('title');
foreach ($children as $v) {
$arr[] = $v->nodeValue;
}
return $arr;
}
示例2: bench2
function bench2()
{
global $XML;
$dom = new domDocument();
$dom->loadxml($XML);
$xp = new domxpath($dom);
$nodes = $xp->query("//title/text()");
foreach ($nodes as $n) {
$arr[] = $n->nodeValue;
}
return $arr;
/*
// simplexml syntax...
$s = simplexml_load_string($XML);
$nodes = $s->xpath("//title");
foreach($nodes as $v) {
$arr[] = reset($v);
}
return $arr;
*/
}
示例3: domDocument
<?php
require_once "dom1.inc";
echo "Test 1: accessing single nodes from php\n";
$dom = new domDocument();
$dom->loadxml($xmlstr);
if (!$dom) {
echo "Error while parsing the document\n";
exit;
}
// children() of of document would result in a memleak
//$children = $dom->children();
//print_node_list($children);
echo "--------- root\n";
$rootnode = $dom->documentElement;
print_node($rootnode);
echo "--------- children of root\n";
$children = $rootnode->childNodes;
print_node_list($children);
// The last node should be identical with the last entry in the children array
echo "--------- last\n";
$last = $rootnode->lastChild;
print_node($last);
// The parent of this last node is the root again
echo "--------- parent\n";
$parent = $last->parentNode;
print_node($parent);
// The children of this parent are the same children as one above
echo "--------- children of parent\n";
$children = $parent->childNodes;
print_node_list($children);
示例4: domDocument
<?php
$xml = '<?xml version="1.0"?><dependencies><dependency dependency_id="0" dependent_id="1"/><dependency dependency_id="4" dependent_id="5"/><dependency dependency_id="5" dependent_id="6"/><dependency dependency_id="9" dependent_id="8"/><dependency dependency_id="10" dependent_id="8"/><dependency dependency_id="12" dependent_id="13"/><dependency dependency_id="12" dependent_id="14"/></dependencies>';
$dom = new domDocument();
$dom->loadxml($xml);
$xpath = new DOMXPath($dom);
$node_list = $xpath->query('//dependencies/dependency[@dependency_id = 0 and @dependent_id = 1]');
$dependencies = $xpath->query('//dependencies')->item(0);
$dependencies->removeChild($node_list->item(0));