0

I know how to extract the data from between two tags or elements but I do not know how to extract the data from within the element itself for example (see this section Tax="0.0" EHF="0.0" Freight="0.0" Handling="0.0" SubTotal="0.72"). Any help would be most appreciated.

<INVTOTAL Tax="0.0" EHF="0.0" Freight="0.0" Handling="0.0" SubTotal="0.72">0.72</INVTOTAL>

1 Answer 1

1

There are a few ways to do it. For example, using xpath, something like

$invoice= '
<root><INVTOTAL Tax="10.0" EHF="0.0" Freight="0.0" Handling="0.0" SubTotal="0.72">0.72</INVTOTAL></root>';
$XMLDoc = new DOMDocument();
$XMLDoc->loadXML($invoice);
$xpath = new DOMXPath($XMLDoc);

$tax = $xpath->query("//INVTOTAL/@Tax");
echo($tax[0]->nodeValue);

Output:

10.0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.