I am working on the following xml file and can't get the namespaces to work in PHP using the SimpleXmlElement or simplexml_load_file
How would I get the seperate cac:InvoiceLine lines parsed as these I need to add into a database as records per invoiceline.
I can see the different namespace when using the getNamespaces() but still I don't get them to split out right.
<?xml version="1.0" encoding="Windows-1252"?><SelfBilledInvoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:SelfBilledInvoice-2" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:ccts="urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2" xmlns:stat="urn:oasis:names:specification:ubl:schema:xsd:DocumentStatusCode-1.0" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:udt="urn:un:unece:uncefact:data:draft:UnqualifiedDataTypesSchemaModule:2">
<cbc:UBLVersionID>2.0</cbc:UBLVersionID>
<cbc:ID>CBF-123</cbc:ID>
<cbc:CopyIndicator>false</cbc:CopyIndicator>
<cbc:IssueDate>2016-07-05</cbc:IssueDate>
<cbc:InvoiceTypeCode>D</cbc:InvoiceTypeCode>
<cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
<cbc:LineCountNumeric>1</cbc:LineCountNumeric>
<cac:BillingReference>
<cac:SelfBilledInvoiceDocumentReference>
<cbc:ID>112.pdf</cbc:ID>
</cac:SelfBilledInvoiceDocumentReference>
</cac:BillingReference>
<cac:AccountingCustomerParty>
<cac:Party>
<cac:PartyIdentification>
<cbc:ID>30276460</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>CB</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:Postbox>123</cbc:Postbox>
<cbc:CityName>City</cbc:CityName>
<cbc:PostalZone>zipcode</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>NL</cbc:IdentificationCode>
<cbc:Name>Nederland</cbc:Name>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID>NL123</cbc:CompanyID>
<cac:TaxScheme>
<cbc:Name>NL VAT</cbc:Name>
</cac:TaxScheme>
</cac:PartyTaxScheme>
</cac:Party>
<cac:AccountingContact>
<cbc:Telephone>0111-1118</cbc:Telephone>
<cbc:Telefax>0111-11118</cbc:Telefax>
</cac:AccountingContact>
</cac:AccountingCustomerParty>
<cac:AccountingSupplierParty>
<cac:Party>
<cac:PartyIdentification>
<cbc:ID>9573703</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>A&E</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName>Street 33</cbc:StreetName>
<cbc:InhouseMail>205</cbc:InhouseMail>
<cbc:CityName>City</cbc:CityName>
<cbc:PostalZone>zone</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>NL</cbc:IdentificationCode>
<cbc:Name>Nederland</cbc:Name>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID>NL222</cbc:CompanyID>
<cac:TaxScheme>
<cbc:Name>NL VAT</cbc:Name>
</cac:TaxScheme>
</cac:PartyTaxScheme>
</cac:Party>
</cac:AccountingSupplierParty>
<cac:PaymentMeans>
<cbc:PaymentMeansCode>AO</cbc:PaymentMeansCode>
<cbc:PaymentDueDate>2016-09-15</cbc:PaymentDueDate>
<cbc:InstructionNote>Totaal af te dragen omzet</cbc:InstructionNote>
<cac:PayerFinancialAccount>
<cbc:ID>NL11RAB11111111</cbc:ID>
<cac:FinancialInstitutionBranch>
<cbc:ID>RABONL1U</cbc:ID>
<cbc:Name>Rabobank</cbc:Name>
</cac:FinancialInstitutionBranch>
</cac:PayerFinancialAccount>
</cac:PaymentMeans>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="EUR">0.66</cbc:TaxAmount>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="EUR">10.94</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="EUR">0.66</cbc:TaxAmount>
<cbc:Percent>6</cbc:Percent>
<cac:TaxCategory>
<cac:TaxScheme>
<cbc:Name>NL VAT</cbc:Name>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
<cac:LegalMonetaryTotal>
<cbc:TaxExclusiveAmount currencyID="EUR">10.94</cbc:TaxExclusiveAmount>
<cbc:PayableAmount currencyID="EUR">11.60</cbc:PayableAmount>
</cac:LegalMonetaryTotal>
<cac:InvoiceLine>
<cbc:ID>79469458</cbc:ID>
<cbc:InvoicedQuantity>1</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="EUR">10.94</cbc:LineExtensionAmount>
<cac:OrderLineReference>
<cbc:LineID>82947243</cbc:LineID>
</cac:OrderLineReference>
<cac:AllowanceCharge>
<cbc:ChargeIndicator>false</cbc:ChargeIndicator>
<cbc:MultiplierFactorNumeric>0.42</cbc:MultiplierFactorNumeric>
<cbc:Amount currencyID="EUR">7.92</cbc:Amount>
</cac:AllowanceCharge>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="EUR">0.66</cbc:TaxAmount>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="EUR">10.94</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="EUR">0.66</cbc:TaxAmount>
<cbc:Percent>6</cbc:Percent>
<cbc:PerUnitAmount currencyID="EUR">18.86</cbc:PerUnitAmount>
<cac:TaxCategory>
<cac:TaxScheme>
<cbc:Name>NL VAT</cbc:Name>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
<cac:Item>
<cbc:Description>TITLE</cbc:Description>
<cac:StandardItemIdentification>
<cbc:ID>9789079995318</cbc:ID>
</cac:StandardItemIdentification>
<cac:AdditionalItemProperty>
<cbc:Name>Afnemer</cbc:Name>
<cbc:Value>ABC</cbc:Value>
</cac:AdditionalItemProperty>
</cac:Item>
<cac:Price>
<cbc:PriceAmount currencyID="EUR">19.99</cbc:PriceAmount>
</cac:Price>
</cac:InvoiceLine>
</SelfBilledInvoice>
This is not a duplicate of the general xml parsing code as this has a number of namespace that prevent the general code to work. The part i don't get in is splitting the namespaces like cac, cbc etc
"; } ?> – Robvk Sep 04 '16 at 13:09