query($query); // A list of mat-6ren">
gpt4 book ai didi

php - 如何在xml和php中只查询一个节点?

转载 作者:行者123 更新时间:2023-11-29 09:01:22 26 4
gpt4 key购买 nike

我有一个代码:

$query = '//Document/Status[. = "Posted"]';
$names = $xpath->query($query); // A list of matched elements

结果

<Document>
<Company>SEC</Company>
<Type description="Misc Customer Invoices">CINV</Type>
<DocumentID>CI_INV000239562</DocumentID>
<DocumentDescription>Invoice</DocumentDescription>
<Status>Posted</Status>
<Owner>42570935</Owner>
<Customer>42570935</Customer>
<Location>42570935</Location>
<Date>20111115</Date>
<DueDate>20111115</DueDate>
<OpenDate>20111115</OpenDate>
<RequiredDate>20111115</RequiredDate>
<TaxCode>AUS GST</TaxCode>
<TaxType>Incl</TaxType>
<TaxRate>10.00</TaxRate>
<CurrencyCode>AUD</CurrencyCode>
<SubTotal>115.00</SubTotal>
<TotalTax>11.50</TotalTax>
<Total>126.50</Total>
<AmountDue>126.50</AmountDue>
<AmountPaid>126.50</AmountPaid>
</Document>

如果我想显示

  <DocumentID>CI_INV000239562</DocumentID>

我应该做什么?

如果我想显示更多节点?例如 AmmountDue ?

$query = '//Document/Status[. = "Posted"]/../DocumentID/AmmountDue';

这可能吗,还是我必须使用其他方法?

谢谢

最佳答案

$query = '//Document/Status[. = "Posted"]/DocumentID';

关于php - 如何在xml和php中只查询一个节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8501162/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com