I have a XML file like the following:
&
You best express that with an Xpath expression:
$owner = ($nodes = $xml_sales->xpath('//FL[@val = "Sales Order Owner"][1]'))
? (string) $nodes[0]
: NULL;
This will give:
Adithya Buddhavarapu
in your case. If the element is not found it is NULL
.
//FL[@val = "Sales Order Owner"][1]
This is the xpath expression. It reads:
Take any FL
element of the document that has the val
attribute with the value "Sales Order Owner"
that is the first element ([1]
).
If you need that per row, it works similar, just run the xpath per row. See SimpleXMLElement::xpath.