class wsdata_simple_xml_processor in Web Service Data 7
Hierarchy
- class \WsData
- class \wsdata_simple_xml_processor
Expanded class hierarchy of wsdata_simple_xml_processor
1 string reference to 'wsdata_simple_xml_processor'
- wsdata_example_wikipedia_field_default_fields in modules/
ws_examples/ wsdata_example_wikipedia/ wsdata_example_wikipedia.features.field.inc - Implements hook_field_default_fields().
File
- ./
wsdata_simple_xml.wsdata.processor.inc, line 3
View source
class wsdata_simple_xml_processor extends WsData {
// Parse the web service response string, and returns a structured data array
public function parse($data) {
if (!isset($data) || empty($data)) {
return;
}
$data = trim($data);
libxml_use_internal_errors(TRUE);
try {
$data = new SimpleXMLElement($data);
if ($data
->count() == 0) {
return array(
$data
->getName() => $data
->__toString(),
);
}
$data = get_object_vars($data);
foreach ($data as $key => $value) {
$data[$key] = $this
->_parsexml($value);
}
} catch (exception $e) {
return FALSE;
}
libxml_use_internal_errors(FALSE);
return $data;
}
function accepts() {
return array(
'xml',
);
}
// XML Parsing helper function, converts nested XML objects into arrays
private function _parsexml($value) {
if (is_object($value) and get_class($value)) {
$value = get_object_vars($value);
foreach ($value as $k => $v) {
$value[$k] = $this
->_parsexml($v);
}
}
elseif (is_array($value)) {
foreach ($value as $key => $xml) {
$value[$key] = $this
->_parsexml($xml);
}
}
return $value;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
WsData:: |
public | property | ||
WsData:: |
protected | property | ||
WsData:: |
protected | property | ||
WsData:: |
public | function | Add data to an empty object or replace all existing data | |
WsData:: |
public | function | Retrieve the value for the given data key. | 1 |
WsData:: |
public | function | ||
WsData:: |
public | function | ||
wsdata_simple_xml_processor:: |
function |
Overrides WsData:: |
||
wsdata_simple_xml_processor:: |
public | function |
Overrides WsData:: |
|
wsdata_simple_xml_processor:: |
private | function |