XML : Create of XML document

I am trying to create a XML document which should have following form:

  <winstrom version="1.0">  <parent>  <parent>  <faktura>  <fakturaitem>  </fakturaitem>  <fakturaitem>  </fakturaitem>  </faktura>  </winstrom>  enter code here    

and now the script creates the parent taqs and now I need to add two (or more) . I would like to add it using following code, but it doesn't work as I want to...

  public function processInvoices(){  $invoices = Mage::getModel('sales/order_invoice')->getCollection()-  >addFieldToFilter('flexibee_synced',array('eq'=>0));    foreach($invoices as $invoice){    $oneInvoiceData = Mage::getModel('sales/order_invoice')->load($invoice->getId());    $xml = $this->createXMLFirmData($oneInvoiceData->getAllItems());    die();    }  }    

So this will call the function createXMLFirmData() which return an array:

This field should be in between taqs ... and now I have other data in $oneInvoiceData which should be inserted in between taqs ... I would like to call an other function which should look like this:

  private function createXMLInvoiceData($orderItem){        $XMLInvoiceData = [];        $XMLInvoiceData['sumZklZakl'] = $orderItem->getGrandTotal();          return $XMLInvoiceData;    }    

So now I should have one parent array and how to add N fields? How should the structure be done so I can call the final function

  private function createXML($XMLFirmData, $XMLInvoiceData){              $dom = new DomDocument('1.0', 'UTF-8');          $dom->formatOutput = true;            $root = $dom->createElement('winstrom');          $root->setAttribute('version','1.0');          $dom->appendChild($root);            $root2 = $dom->createElement('polozkyFaktury');          $root->appendChild($root2);              foreach($fieldWithData as $x => $xValue){                $item = $dom->createElement($x);              $root2->appendChild($item);                $text = $dom->createTextNode($xValue);              $item->appendChild($text);            }                $output_xml = $dom->saveXML();          header('Content-Type: application/xml');          return $output_xml;        }    

No comments:

Post a Comment