本文整理汇总了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));