I have a problem whereby I wish to display a City and Country. I have used the following php in a string, but this displays the word City. How can I display the words Sofia and Bulgaria?
<?php
$item["FIELDS/FIELD/NAME"]
?>
Below is an excerpt from the xml:
<products>
- <product>
- <fields>
- <field>
<name>City</name>
<value>Sofia</value>
</field>
- <field>
<name>Country</name>
<value>Bulgaria</value>
</field>
</fields>
</product>
</products>
Thank you Dave,
How stupid am I! I didn't realise that the actual paths that are needed in order to display the xml items are actually shown on the Magic Parser DEMO page. I have been using the DEMO page to test the validity of the xml files to display, but failed to notice that the actual paths are shown.
Hi,
Where this is the case, Magic Parser resolves additional duplicate key names by appending @n to the end. I've coppied your example XML into the demo script, and you can see the results on this page
http://www.magicparser.com/demo?fileID=446483A693DE7&record=1
(please note, the above demo link will expire shortly)
Provided that your XML always contains the fields in that order, you would be able to display Sofia, Bulgaria as follows (within your record handler function)
print $item["FIELDS/FIELD/VALUE"].",".$item["FIELDS/FIELD/VALUE@1"];
If you cannot guarantee the order then the code is slightly more complicated, but still possible as you have to match the number after the @symbol with the field name. In most cases, this method will work fine.
Cheers,
David.