In the xform xml i want to parse xml and access the id of node. It's the xform xml and i want to access the id of node test_geopoint (id=test_geopoint). But the node name will change for each xform xml.
<?php
$xmlstr = <<<XML <?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<h:head>
<h:title>test_geopoint</h:title>
<model>
<instance>
<test_geopoint id="test_geopoint">
<name/>
<geopoint/>
<meta>
<instanceID/>
</meta>
</test_geopoint>
</instance>
</h:body>
</h:html> $XML;
i tried the code like this, but not access the id of node after the <instance>.
$movies = new SimpleXMLElement($xmlstr);
echo $movies->model->instance->children()[0]['id'];
and
echo $movies->head->title->model->instance->children()[0]['id'];
How can retrieve id of node next to <instance>
in php ?
The below example is the same as you expecting, use it the same way I have accessed, the
name
in a array. You are suppose to mention asinstanceId