hello, I need to add items in the 'ide' element, so that it looks like the example below saving in XML (thank you!).
The example I need:
<ide> <cUF>43</cUF> <cCT>00000004</cCT> <CFOP>6353</CFOP>... </ide>
In the current situation, Im getting only <cUF>:
<?xml version="1.0" encoding="UTF-8"?> <CTe xmlns="http://www.portalfiscal.inf.br/cte"> <infCte versao="3.00" Id="CTe43120178408960000182570010000000041000000047"> <ide><cUF>43</cUF></ide> </infCte> </CTe>
array
$data = array(
'name' => 'CTe',
'attributes' => array(
'xmlns' => '...cte',),array(
'name' => 'infCte',
'attributes' => array(
'versao' => '3.00',
'Id' => 'CTe43120178408960000182570010000000041000000047',
),array(
'name' => 'ide',
array(
'name' => "cUF",
'value' => '43',
'name' => '<cCT>',
'value' => '00000004',
),
),
),
);
passing data to XML
function generate_xml_element( $dom, $data ) {
if ( empty( $data['name'] ) )
return false;
// Create the element
$element_value = ( ! empty( $data['value'] ) ) ? $data['value'] : null;
$element = $dom->createElement( $data['name'], $element_value );
// Add any attributes
if ( ! empty( $data['attributes'] ) && is_array( $data['attributes'] ) ) {
foreach ( $data['attributes'] as $attribute_key => $attribute_value ) {
$element->setAttribute( $attribute_key, $attribute_value );
}
}
// Any other items in the data array should be child elements
foreach ( $data as $data_key => $child_data ) {
if ( ! is_numeric( $data_key ) )
continue;
$child = generate_xml_element( $dom, $child_data );
if ( $child )
$element->appendChild( $child );
}
return $element;
}
$doc = new DOMDocument('1.0','UTF-8');
$child = generate_xml_element( $doc, $data );
if ( $child)$doc->appendChild( $child );
$doc->formatOutput = true;
$xml = $doc->saveXML();
$doc->save('contas.xml');