2011-05-16 40 views
2

XML文件:DOMXPath - 查询

<Domain Domaindetails="This tree display the domain we work">Root element 
<Insurance> 
    <InsuranceQ> 
     <Devs>4</Devs> 
     <QA>1</QA> 
     <Total>5</Total> 
    </InsuranceQ> 
    <?billResource bill()?> 
    <QuoteX/> 
    <ProgressiveLeads> 
     <Devs>3</Devs> 
     <Total>6</Total> 
     <QA>3</QA> 
    </ProgressiveLeads> 
</Insurance> 
<BI> 
    <MoboM/> 
    <CloudFW> 
     <Devs>4</Devs> 
     <QA>4</QA> 
     <Total>8</Total> 
    </CloudFW> 
    <?billResource bill()?> 
</BI> 
<Ecommerce> 
    <USEcom/> 
    <LXEcom/> 
</Ecommerce> 
<extrainfo>Co > S&S </extrainfo> 
</Domain> 

遍历下保险领域的项目,因此写了下面的代码

$dom = new DOMDocument('1.0'); 
$dom->load('project.xml'); 
$xpath = new DOMXPath($dom); 

$nodeList=$xpath->query('//Domain/Insurance'); 

foreach($nodeList as $node) 
{ 

    echo $node->nodeValue; 
    echo '<br/>'; 
} 

它显示空的结果。我的XML有什么问题吗?上面的代码导致415 [devs,qa,total nodes]不是预期的输出。

我想举报 InsuranceQ QuoteX Progressivelead as output。

有人可以让我知道我做错了......

感谢, Priti

回答

0

首先,格式化代码(XML)将有助于理解问题的速度更快。 好的。回到你的问题,你可以尝试//Domain/Insurance/child::*获得节点<Insurance>的所有孩子。

您的XPath未返回预期结果,因为您未选择节点<Insurance>的子节点,而只是选择了<Insurance>节点。

希望这会有帮助

+0

不,它没有帮助我...它仍然显示我415 – user269867 2011-05-17 04:49:58