I am going to be converting XML to JSON as described here. I need to pass that method a string and I can't work out how to convert my XPath result to a string.
I am trying to extract all children of a specific parent element, [name=bar], from an XML file that is formatted like this:
<items> <item name="foo"> <element>1</element> <element> <child>c1</child> </element> <element>2</element> </item> <item name="bar"> <element>1</element> <element> <child>c1</child> </element> <element>2</element> </item> </items> I can access the node I want:
$xmlfile = simplexml_load_file('xmlfile.xml'); $item = $productsXml->xpath('//item[@name="bar"]'); // Returns an array I would like to convert the result to a string:
<item name="bar"> <element>1</element> <element> <child>c1</child> </element> <element>2</element> </item> Any help would be appreciated.
implode()function php.net/manual/en/function.implode.php