我有这个xml:
<Item id="3" idLevel="3">
<Label qualifier="Usual">
<LabelText language="ALL">BE01</LabelText>
</Label>
<Label qualifier="Usual">
<LabelText language="EN">RÉGION DE BRUXELLES-CAPITALE / BRUSSELS HOOFDSTEDELIJK GEWEST</LabelText>
</Label>
</Item>
<Item id="4" idLevel="3">
<Label qualifier="Usual">
<LabelText language="ALL">BE001</LabelText>
</Label>
<Label qualifier="Usual">
<LabelText language="EN">VLAAMS GEWEST</LabelText>
</Label>
</Item>
<Item id="123" idLevel="3">
<Label qualifier="Usual">
<LabelText language="ALL">RO001</LabelText>
</Label>
<Label qualifier="Usual">
<LabelText language="EN">MACROREGIUNEA DOI</LabelText>
</Label>
</Item>
我想获取<LabelText language="EN">
邻居<LabelText language="ALL">
以“BE”开头并且后面有 3 个数字的值。
在这种情况下,我将在示例中获得第二个 xml 元素的值:VLAAMS GEWEST
我有一个想法如何以丑陋的方式处理它,但我相信应该有更灵活和优雅的方式来做到这一点:
$crawler = new Crawler();
$crawler->addXmlContent($xml);
$crawler = $crawler->filterXPath('//Item[@idLevel="3"]');
foreach ($crawler as $domElement) {
// here I check if inside element's neighbour has value of "BE" and three numbers after with regex
}
有没有办法处理它DomCrawler
而不是迭代所有元素并检查每个元素?