I have an XML document which is well defined with an XSD file. The xml document contains content similar to the below:
<foo>
<bar>text <element a="1" b="2" c="3" /> and some more text</bar>
<bar>Just text</bar>
</foo>
I was wanting to use PHP to parse it to just bring back one of the attribute values (which will be decided elsewhere in the code) inline with the rest of the text, for this example I would want "B" and the output should be:
"text 2 and some more text"
"Just text"
I am having an issue getting the output in this format as I cannot find a way to either split the nodes text so that I can insert the attribute value or output the pure xml of the node.
My preference would be to use PHP's DOMDocument method to do this. While I have not learnt XPath I would be willing to learn it, if it would make this task possible. I would also consider changing the format of the nested node although this would be a last resort.
I am using DOMdocument to find the node:
$xml= new DOMDocument();
$xml->load(XMLPATH);
$node = $xml->getElementsByTagName("element")->item(0);
Then all of the following ignore the nested element:
$node->nodeValue;
$node->C14N();
I have also followed this guide to no avail: How to get innerHTML of DOMNode?
Thanks for your help.