这是我的XML代码的一部分,我的XML中有85个w:p
个节点,但只有少数<w:p>
个节点有w:listPr
个子节点(如下所示)。
我需要PHP中的代码,它可以检查每个<w:p>
节点是否有w:listPr
子节点,如果它有“执行特定任务”,否则“执行另一个任务”..所以请帮助我我被困在这一个星期。
这是我尝试将PHP转换为HTML的代码。我没有得到如何检查节点是否退出节点
<?php
error_reporting(0);
$doc = new DOMDocument();
$doc->load('test3.xml');
$xpath = new DOMXpath($doc);
$xpath->registerNamespace("w", "http://schemas.microsoft.com/office/word/2003/wordml");
$x = new DOMXpath($doc);
$x->registerNamespace("wx", "http://schemas.microsoft.com/office/word/2003/auxHint");
for($i=0;$i<85;$i++){
$errorNodes = $x->evaluate("//wx:sect/w:p")->item($i)->getElementsByTagName('w:listPr');
if($errorNodes){echo ('li there'); } else{ echo ('li not there');}
$no_of_childs = $x->evaluate("//wx:sect/w:p")->item($i)->childNodes->length;
if($no_of_childs>3){
if(($x->evaluate("//wx:sect/w:p/w:pPr/w:pStyle")->item($i)->attributes[0]->nodeValue)==2){
echo "<h1>".$x->evaluate("//wx:sect/w:p")->item($i)->nodeValue."</h1>";
}
else if(($x->evaluate("//wx:sect/w:p/w:pPr/w:pStyle")->item($i)->attributes[0]->nodeValue)==3){
echo "<h2>".$x->evaluate("//wx:sect/w:p")->item($i)->nodeValue."</h2>";
}
else if($no_of_childs==5){
echo "<h3>".$x->evaluate("//wx:sect/w:p")->item($i)->nodeValue."</h3>";
}
}
else{
echo "<p>".$x->evaluate("//wx:sect/w:p")->item($i)->nodeValue."</p>";
}
}
?>
<w:p>
<w:r>
<w:t>In a normal joint, articular cartilage allows for smooth movement within the joint, whereas in an arthritic knee the cartilage itself becomes thinner or completely absent. In addition, the bones become thicker around the edges of the joint and may form bony “spurs”. These factors can cause pain and restricted range of motion in the joint.</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t>Your doctor may advise total knee replacement if you have:</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:listPr>
<w:ilvl w:val="0" />
<w:ilfo w:val="1" />
</w:listPr>
<w:ind w:left="993" />
</w:pPr>
<w:r>
<w:t>Severe knee pain which limits your daily activities (such as walking, getting up from a chair or climbing stairs).</w:t>
</w:r>
</w:p>
答案 0 :(得分:0)
这是我尝试检查节点内的节点的代码
<?php for($i=0;$i<85;$i++){
$gh=$x->evaluate("//wx:sect/w:p[".($i+1)."]/w:pPr/w:listPr/w:ilvl")->item(0)->attributes[0]->nodeValue;
$g5=$x->evaluate("//wx:sect/w:p[".$i."]/w:pPr/w:listPr")->item(0)->childNodes->length;
if($gh!=null){
echo 'exist at paragrah number '.$i." value :".$gh."<br>";
}
else{
echo 'notexist at paragrah number '.$i." value :".$gh."<br>";
}
} ?>