如何将标签引用分配给文本?
$xml =<<<EOT
<?xml version="1.0"?>
<root>
<section name="Section2">
<category id="category1_of_section2" name="msn">
teste
<arti name="article2">value1</arti>
<arti name="article3">value2 <sref ref="article6" />value6 <sref ref="article7" />value7</arti>
<arti name="article4">value3 <sref ref="article8" />value8</arti>
</category>
<category id="Category2_of_section2" name="webcare">
<arti name="param3">value4</arti>
</category>
</section>
</root>
EOT;
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->loadXML($xml);
$params = $dom->getElementsByTagName('section'); // Find Sections
$k=0;
$numero2=0;
$roomStr3="";
foreach ($params as $param)
{
echo "Section Attribute :-> ".$params->item($k)->getAttribute('name')."<br>";
$params2 = $params->item($k)->getElementsByTagName('category');
$i=0;
foreach ($params2 as $p)
{
echo " - Category Attribute Name :-> ".$params2->item($i)->getAttribute('name')."<br>";
$params3 = $params2->item($i)->getElementsByTagName('arti');
$j=0;
foreach ($params3 as $p2)
{
echo " - Article Attribute Name : ".$params3->item($j)->getAttribute('name')."";
echo " Value : ".$params3->item($j)->nodeValue."<br>";
var_dump($params3->item($j));
$elems3 = $params3->item($j)->getElementsByTagName('sref');
$j++;
}
$i++;
}
$k++;
}
//Print
Section Attribute :-> Section2
- Category Attribute Name :-> msn
- Article Attribute Name : article2 Value : value1
- Article Attribute Name : article3 Value : value2 value6 value7
- Article Attribute Name : article4 Value : value3 value8
- Category Attribute Name :-> webcare
- Article Attribute Name : param3 Value : value
如何显示参考?
前任:
文章属性名称:article3 值:value2 ref="article6": value6 ref="article7": value7
文章属性名称:article4 值:value3 ref="article8": value8