I have a code :
$query = '//Document/Status[. = "Posted"]';
$names = $xpath->query($query); // A list of matched elements
result
<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>
If I want to display
<DocumentID>CI_INV000239562</DocumentID>
only
What should I do ?
If I want more node to be displayed ? for example AmmountDue ?
$query = '//Document/Status[. = "Posted"]/../DocumentID/AmmountDue';
Is this possible or I must use another method ?
Thanks
There are few ways to do this, here is one of the example :-
$query = '//Document/Status[. = "Posted"]/../DocumentID';
...
$names = $xpath->query($query);
foreach ($names as $name)
{
$node = $name->nodeValue; // string of "CI_INV000239562"
}
To seek for multiple node name :-
//Document/Status[. = "Posted"]/../*[self::DocumentID or self::AmountDue]
$query = '//Document/Status[. = "Posted"]/DocumentID';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.