public function testInvalidAttributesDynamic() { $actual = array('foo' => array('@content' => 'Some'), 'bar' => 'Text'); $expected_xml = '<root><foo></foo><bar>Text</bar></root>'; $actual_xml = $this->array2xml->convert($actual); $actual = new DOMDocument(); $actual->preserveWhiteSpace = false; $actual->loadXML($actual_xml); $expected = new DOMDocument(); $expected->preserveWhiteSpace = false; $expected->loadXML($expected_xml); $this->assertEqualXMLStructure($expected->firstChild, $actual->firstChild, true); }
public function generateXML($array) { $xml = Array2xml::createXML('seller', $array); return $xml->saveXML(); }
/** * converts PHP array into XML * * @param $result php array * @return xml * @access public */ function arrayToXML($result) { if (is_array($result)) { $array2XML = new Array2xml(); $array2XML->setArray($result); return $array2XML->saveArray("Result"); } else { return "<?xml version='1.0' encoding='utf-8'?><error>ERROR: server behaved unexpectedly !!</error>"; } }
public function getXML() { $array2xml = new Array2xml(); $array2xml->setRootName('items'); $array2xml->setNumericElement('item'); $array2xml->setSkipNumeric(false); $namespaces = array( 'xmlns' => "http://example.com/ns/#", 'xmlns:ic' => "http://imi.ipa.go.jp/ns/core/2", 'xmlns:dct' => "http://purl.org/dc/terms/", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xsi:noNamespaceSchemaLocation' => "./schema.xsd", ); $id = array(); $output = array(); foreach ( $this->items as $item ) { if ( $this->checkHeaderSkip() ) { continue; } $not_empty = false; foreach($item as $cell){ if(!empty($cell)){ $not_empty = true; break; } } if(!$not_empty){ continue; } $id[] = array('id' => $this->project['eg:vocabulary']['eg:uri'] . $this->getSubject($item)); $output[] = $this->setPropertyRecursive( $item, $this->property ); } $array2xml->setElementsAttrs($id); $array2xml->setRootAttrs($namespaces); return $array2xml->convert($output); }
function convert_xml($xml_result, $what) { global $xml_dir, $xml_name; error_reporting(E_ALL & ~E_DEPRECATED & ~E_WARNING & ~E_NOTICE & ~E_STRICT); $now = date('_Y.m.d_h-i-s_A_'); // current date and time , but writeable as file name on all OS // convert the result array to XML file $array2XML = new Array2xml(); $array2XML->setArray($xml_result); // store the online XML result if ($array2XML->saveArray("" . $xml_dir . "/" . $what . "_" . $xml_name . "", "" . $what . "_results")) { } else { if ($debug == '2') { echo "<small>Attention: Unable to create the XML result file <span class='blue'>{$xml_name}</span> in subfolder <span class='blue'>{$xml_dir}</span></small><br />"; } } // store the XML cached result if ($array2XML->saveArray("" . $xml_dir . "/stored/" . $now . "" . $what . "_" . $xml_name . "", "" . $now . "" . $what . "_results")) { } else { if ($debug == '2') { echo "<small>Attention: Unable to create the XML cache result file <span class='blue'>{$xml_name}</span> in subfolder <span class='blue'>{$xml_dir}</span></small><br />"; } } return; }
function arrayToXML($result) { $array2XML = new Array2xml(); $array2XML->setArray($result); return $array2XML->saveArray("Result"); }