goetas-webservices / xsd2php

Convert XSD into PHP classes and JMS serializer definitions
MIT License
238 stars 93 forks source link

Namespace for array element - xml_list #118

Closed giansalex closed 4 years ago

giansalex commented 4 years ago

Hello, I don't know if this is an error, i try xsd2php with UBL 2.1 xsd

This is autogenerated yaml for InvoiceLine section InvoiceType.yaml

        invoiceLine:
            expose: true
            access_type: public_method
            serialized_name: InvoiceLine
            xml_element:
                cdata: false
                namespace: 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'
            accessor:
                getter: getInvoiceLine
                setter: setInvoiceLine
            xml_list:
                inline: true
                entry_name: InvoiceLine
                namespace: 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2'
            type: array<TestNs\Ubl\CommonAggregateComponents\InvoiceLine>

After serialization, i get:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
  <cbc:UBLVersionID>2.1</cbc:UBLVersionID>
  <cbc:CustomizationID>2.0</cbc:CustomizationID>
  <cbc:ID>F001-2121</cbc:ID>
  <InvoiceLine>
    <cbc:ID>1</cbc:ID>
    <cbc:InvoicedQuantity>12.0</cbc:InvoicedQuantity>
  </InvoiceLine>
  <InvoiceLine>
    <cbc:ID>2</cbc:ID>
    <cbc:InvoicedQuantity>7.342</cbc:InvoicedQuantity>
  </InvoiceLine>
</Invoice>

<InvoiceLine> don't have prefix cac

Then I change xml_list:namespace same to xml_element:namespace

            xml_list:
                inline: true
                entry_name: InvoiceLine
                namespace: 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'

After, i get expected result:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
  <cbc:UBLVersionID>2.1</cbc:UBLVersionID>
  <cbc:CustomizationID>2.0</cbc:CustomizationID>
  <cbc:ID>F001-2121</cbc:ID>
  <cac:InvoiceLine>
    <cbc:ID>1</cbc:ID>
    <cbc:InvoicedQuantity>12.0</cbc:InvoicedQuantity>
  </cac:InvoiceLine>
  <cac:InvoiceLine>
    <cbc:ID>2</cbc:ID>
    <cbc:InvoicedQuantity>7.342</cbc:InvoicedQuantity>
  </cac:InvoiceLine>
</Invoice>
goetas commented 4 years ago

This might be a bug in this library.

The InvoiceLine element in urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 is imported using ref from urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2, probably it should stay in the urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2 namespace.

anto-acube commented 4 years ago

Hello, I'm experiencing the same issue, I think that this PR is related https://github.com/goetas-webservices/xsd2php/pull/108

goetas commented 4 years ago

fixed in 0.4.0