0
私はXMLとPHPで作業しています。私は2つの<customer>
顧客とこのXML形式にPHPの配列を取得しようとしていますが、私は1を得ることができますが、配列内の2人の顧客に対してそれを行う方法は分かりません。XML構造体を正しく取得できません。
<?xml version="1.0"?>
<NewSLSCase>
<Identification CientNo="4xxx" CLientBatchNo="1" IJBatchNo="1" HubNo="201048" ClientEmailAddress1="[email protected]" ClientEmailAddress2="[email protected]"/>
<LedgerSet>
<Ledger ProductionUnit="04" LedgerNo="4xxxxx">
<CustomerSet>
<Customer No="123456" Name="Farhana" Address1="Myhouse" ZipCode="40100" City="Vantaa" LanguageCode="FIN" CountryCode="FI" VatNo="01011-111A" TypeCode="C"/>
<Customer No="123457" Name="Asiakas Anna" Address1="Asiakastie 2" ZipCode="00100" City=" Helsinki" LanguageCode="FIN" CountryCode="FI" VATNo="010111-111A" TypeCode="C"/>
</CustomerSet>
<InvoiceSet>
<Invoice InvoiceNo="123456"/>
<InvoiceHeader InvoiceHeaderType="L" InvoiceCustomerNo="123456" InvoiceCurrency="EUR" InvoiceDate="2011-04-08" InvoiceDueDate="2011-05-15" InvoiceAmount="57.00" ClientOCRReference="908000101800031186" InvoiceReferenceText3="150,00" InvoiceReferenceText4="Laskuille tulostuva" InvoiceReferenceText5="IBAN" InvoiceReferenceText6="BIC"/>
</InvoiceSet>
</Ledger>
</LedgerSet>
</NewSLSCase>
私はちょうど1つを得るためのコードを書いた `が、別のものを追加すると、私は本当にオフに確認していないものです。
ここでは配列ですが、それ以来全体をコピーしていませんでしたが、テストのためにその一部を使用しています。ここで
array(2) (
[0] => stdClass object {
ID => (string) 177835
currency => (string) Asiakas Anna
type => (string) Asiakastie 2
}
[1] => stdClass object {
ID => (string) 177840
Name=> (string) Farhana
Address=> (string) Myhouse
.....
私を与えるもの上記のコード、全体のXML形式
$result = $this->invoice_page->getInvoiceByID('20241'); //this is the array
$xml = new DomDocument('1.0');
$xml->formatOutput = true;
$NewSLSCase = $xml->createElement("NewSLSCase");
$xml->appendChild($NewSLSCase);
$Identification = $xml->createElement("Identification");
$Identification->setAttribute("CientNo","4xxx");
$Identification->setAttribute("CLientBatchNo", "1");
$Identification->setAttribute("CLientBatchNo", "1");
$Identification->setAttribute("IJBatchNo", "1");
$Identification->setAttribute("HubNo", "201048");
$Identification->setAttribute("ClientEmailAddress1", "[email protected]");
$Identification->setAttribute("ClientEmailAddress2", "[email protected]");
$NewSLSCase->appendChild($Identification);
$LedgerSet = $xml->createElement("LedgerSet");
$NewSLSCase->appendChild($LedgerSet);
$Ledger = $xml->createElement("Ledger");
$Ledger->setAttribute("ProductionUnit","04");
$Ledger->setAttribute("LedgerNo", "4xxxxx");
$LedgerSet->appendChild($Ledger);
$CustomerSet = $xml->createElement("CustomerSet");
$Ledger->appendChild($CustomerSet);
$Customer = $xml->createElement("Customer");
$Customer->setAttribute("No","123456");
$Customer->setAttribute("Name", $result['Fullname']);
$Customer->setAttribute("Address1", $result['Address_street']);
$Customer->setAttribute("ZipCode", $result['Address_zip']);
$Customer->setAttribute("City",$result['Address_city']);
$Customer->setAttribute("LanguageCode", "FIN");
$Customer->setAttribute("CountryCode","FI");
$Customer->setAttribute("VatNo", "01011-111A");
$Customer->setAttribute("TypeCode","C");
$CustomerSet->appendChild($Customer);
$InvoiceSet = $xml->createElement("InvoiceSet");
$Ledger->appendChild($InvoiceSet);
$Invoice = $xml->createElement("Invoice");
$Invoice->setAttribute("InvoiceNo","123456");
$InvoiceSet->appendChild($Invoice);
$InvoiceHeader = $xml->createElement("InvoiceHeader");
$InvoiceHeader->setAttribute("InvoiceHeaderType", "L");
$InvoiceHeader->setAttribute("InvoiceCustomerNo","123456");
$InvoiceHeader->setAttribute("InvoiceCurrency", "EUR");
$InvoiceHeader->setAttribute("InvoiceDate","2011-04-08");
$InvoiceHeader->setAttribute("InvoiceDueDate", "2011-05-15");
$InvoiceHeader->setAttribute("InvoiceAmount","57.00");
$InvoiceHeader->setAttribute("ClientOCRReference", "908000101800031186");
$InvoiceHeader->setAttribute("InvoiceReferenceText3","150,00");
$InvoiceHeader->setAttribute("InvoiceReferenceText4","Laskuille tulostuva");
$InvoiceHeader->setAttribute("InvoiceReferenceText5",$result['IBAN']);
$InvoiceHeader->setAttribute("InvoiceReferenceText6",$result['BIC']);
$InvoiceSet->appendChild($InvoiceHeader);
echo "<xmp>".$xml->saveXML()."</xmp>";
この
<?xml version="1.0"?>
<NewSLSCase>
<Identification CientNo="4xxx" CLientBatchNo="1" IJBatchNo="1" HubNo="201048" ClientEmailAddress1="[email protected]" ClientEmailAddress2="[email protected]"/>
<LedgerSet>
<Ledger ProductionUnit="04" LedgerNo="4xxxxx">
<CustomerSet>
<Customer No="123456" Name="Farhana" Address1="Myhouse" ZipCode="40100" City="Vantaa" LanguageCode="FIN" CountryCode="FI" VatNo="01011-111A" TypeCode="C"/>
</CustomerSet>
<InvoiceSet>
<Invoice InvoiceNo="123456"/>
<InvoiceHeader InvoiceHeaderType="L" InvoiceCustomerNo="123456" InvoiceCurrency="EUR" InvoiceDate="2011-04-08" InvoiceDueDate="2011-05-15" InvoiceAmount="57.00" ClientOCRReference="908000101800031186" InvoiceReferenceText3="150,00" InvoiceReferenceText4="Laskuille tulostuva" InvoiceReferenceText5="IBAN" InvoiceReferenceText6="BIC"/>
</InvoiceSet>
</Ledger>
</LedgerSet>
</NewSLSCase>
されている私は、2人の顧客情報を取得するためにforeach
を追加する方法を見当もつかない。顧客による
ありがとう!できます!!! – FaF