I need to get the value of the custom_field "NewTitle" (ID 6) which is nested inside the child "custom_fields" of the following XML:
<issues total_count="63" offset="0" limit="100" type="array">
<issue>
<id>65</id>
<project id="7" name="ProjectName"/>
<tracker id="7" name="TrackerName"/>
<subject>MySubject</subject>
...
<custom_fields type="array">
<custom_field id="4" name="OrderType">
<value>Project</value>
</custom_field>
<custom_field id="26" name="ExtID">
<value>246558</value>
</custom_field>
<custom_field id="25" name="Area" multiple="true">
<value type="array">
<value>Process</value>
<value>System</value>
</value>
</custom_field>
<custom_field id="6" name="NewTitle">
<value>ABCDEF</value>
</custom_field>
...
<custom_field id="20" name="KST">
<value/>
</custom_field>
<custom_field id="11" name="LKF">
<value>3</value>
</custom_field>
<custom_field id="17" name="Link">
<value>XXX</value>
</custom_field>
</custom_fields>
<created_on>2015-12-14T08:00:03Z</created_on>
<updated_on>2016-01-28T09:07:20Z</updated_on>
<closed_on/>
</issue>
</issues>
Can somebody tell me how to do that with PHP? I only managed to display values of the main fields. For example the subject:
foreach ($xml->issue as $issue){
if((string) $issue->tracker['id'] == 7){
echo $issue->subject.'<br/>';
}
}
Use SimpleXML combined with an xpath:
$xml = simplexml_load_string($your_xml_here);
$fields = $xml->xpath("//custom_field[@name='NewTitle']");
foreach ($fields as $field) {
// do sth. useful here
}