Jump to content

Help pulling value from XML block using SimpleXML


goomba441

Recommended Posts

Hi there:

 

I have a PDF form that generates an XFDF file (form field valies in XML form) and I am passing it to PHP for processing. I am having trouble pulling a specific value from the XML block because of the way that the XML data is generated and organized. Please see a sample of the XML block below:

 

'test.xml' file:

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<annots/><fields>

<field name="Non">
<value>Off</value>
</field>

<field name="PayRequest">
<value>XYZ</value>
</field>

 

From the above XML snip it, once it's sent to PHP, I would like to somehow reference the "PayRequest" field value and retrieve the value "XYZ" and assign it to a variable. I have been kicking around some code that I thought should work, but doesn't appear to. If anyone could offer any insight to get it working that would be greatly appreciated.

 

PHP Code:

$prq_ret = simplexml_load_file('test.xml');
foreach($prq_ret->xpath("//field[@name='PayRequest']") as $item) {

$row = simplexml_load_string($item->asXML());
//print $item->value;
print $row;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.