开发者

DOMXPath - query

开发者 https://www.devze.com 2023-03-06 10:55 出处:网络
XML File: <Domain Domaindetails=\"This tree display the domain we work\">Root element <Insurance>

XML File:

   <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>
<E开发者_StackOverflow社区commerce>
    <USEcom/>
    <LXEcom/>
</Ecommerce>
<extrainfo>Co > S&S </extrainfo>
</Domain>

Traversing the projects under Insurance domain Hence wrote following code

$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/>';
}

It shows empty result. Am I having something wrong in my XML ?. The above code result in 415[devs,qa,total nodes] which is not the expected output.

I want to list InsuranceQ QuoteX Progressivelead as output.

Can someone let me know what I am doing wrong...

Thanks, Priti


Firstly, formatted code (XML) would help understand problem faster. Ok. Coming back to your question, you can try //Domain/Insurance/child::* to get all the children of node <Insurance>.

Your XPath did not return expected results because you are not selecting children of node <Insurance>, you are just selecting <Insurance> node.

Hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消