goetas-webservices / xsd2php

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

xml_namespaces property #173

Closed potatocode420 closed 5 months ago

potatocode420 commented 5 months ago

Hello, is there a way to populate xml_namespaces property for the JMS serializer metadata via the xsd2php configuration? Currently my configuration is generating PHP classes and metadata properly except for the lack of xml_namespaces attribute. For reference, here is my config file:

xsd2php:
  namespaces:
    'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2': 'Invoicing\UBLSchema\v21\MainDoc'
    'urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2': 'Invoicing\UBLSchema\v21\Common\ExtensionComponents'
    'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2': 'Invoicing\UBLSchema\v21\Common\BasicComponents'
    'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2': 'Invoicing\UBLSchema\v21\Common\AggregateComponents'
    'urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2': 'Invoicing\UBLSchema\v21\Common\SignatureComponents'
    'urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2': 'Invoicing\UBLSchema\v21\Common\SignatureAggregateComponents'
    'urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2': 'Invoicing\UBLSchema\v21\Common\SignatureBasicComponents'
    'urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2': 'Invoicing\UBLSchema\v21\Common\UnqualifiedDataTypes'
    'urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2': 'Invoicing\UBLSchema\v21\Common\QualifiedDataTypes'
    'urn:un:unece:uncefact:data:specification:CoreComponentTypeSchemaModule:2': 'Invoicing\UBLSchema\v21\Common\CoreComponentType'
    'http://www.w3.org/2000/09/xmldsig#': 'Invoicing\Signing\Schema'
    'http://uri.etsi.org/01903/v1.3.2#': 'Invoicing\Signing\Schema'
    'http://uri.etsi.org/01903/v1.4.1#': 'Invoicing\Signing\Schema'
  destinations_php: 
    'Invoicing\UBLSchema': src/UBLSchema
    'Invoicing\Signing\Schema': src/Signing/Schema
  destinations_jms:
    'Invoicing\Signing\Schema': metadata/Signing
    'Invoicing\UBLSchema\v21\MainDoc': metadata/v21/MainDoc
    'Invoicing\UBLSchema\v21\Common\ExtensionComponents': metadata/v21/Common/ExtensionComponents
    'Invoicing\UBLSchema\v21\Common\BasicComponents': metadata/v21/Common/BasicComponents
    'Invoicing\UBLSchema\v21\Common\AggregateComponents': metadata/v21/Common/AggregateComponents
    'Invoicing\UBLSchema\v21\Common\SignatureComponents': metadata/v21/Common/SignatureComponents
    'Invoicing\UBLSchema\v21\Common\SignatureAggregateComponents': metadata/v21/Common/SignatureAggregateComponents
    'Invoicing\UBLSchema\v21\Common\SignatureBasicComponents': metadata/v21/Common/SignatureBasicComponents
    'Invoicing\UBLSchema\v21\Common\UnqualifiedDataTypes': metadata/v21/Common/UnqualifiedDataTypes
    'Invoicing\UBLSchema\v21\Common\QualifiedDataTypes': metadata/v21/Common/QualifiedDataTypes
    'Invoicing\UBLSchema\v21\Common\CoreComponentType': metadata/v21/Common/CoreComponentType
  naming_strategy: short
  path_generator: psr4
  configs_jms:
    xml_cdata: false 
goetas commented 5 months ago

The xml_namespaces is not meant to be defined manually, it is automatically decided by the serializer based on namespaces used.

I'm closing the issue, feel free to elaborate more your specific usecase if my answer is not clear enough

potatocode420 commented 5 months ago

but the serializer gets xml_namespaces from the config. without defining xml_namespaces, I am not able to serialize the XML properly. image

Below is the result with xml_namespaces:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:ubl="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:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
  <ext:UBLExtensions>
    <ext:UBLExtension>
      <i_d>PHPUNIT</i_d>
    </ext:UBLExtension>
  </ext:UBLExtensions>
  <cbc:ID>PHPUNIT</cbc:ID>
  <cbc:Note>Note No. 2!!!</cbc:Note>
  <cac:AccountingSupplierParty/>
  <cac:AccountingCustomerParty/>
  <cac:LegalMonetaryTotal>
    <cbc:PayableAmount currencyID="EUR">15.35</cbc:PayableAmount>
  </cac:LegalMonetaryTotal>
  <cac:InvoiceLine>
    <cbc:ID>PHPUNIT</cbc:ID>
    <cbc:LineExtensionAmount>555.0</cbc:LineExtensionAmount>
    <cac:Item>
      <cbc:Name>PHPUNIT</cbc:Name>
    </cac:Item>
  </cac:InvoiceLine>
</Invoice>

and the following is without xml_namespaces:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
  <ns-d82937bf:UBLExtensions xmlns:ns-d82937bf="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
    <ns-d82937bf:UBLExtension>
      <i_d>PHPUNIT</i_d>
    </ns-d82937bf:UBLExtension>
  </ns-d82937bf:UBLExtensions>
  <ns-e4c2ceaa:ID xmlns:ns-e4c2ceaa="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">PHPUNIT</ns-e4c2ceaa:ID>
  <ns-e4c2ceaa:Note xmlns:ns-e4c2ceaa="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">Note No. 2!!!</ns-e4c2ceaa:Note>
  <ns-716b5bb3:AccountingSupplierParty xmlns:ns-716b5bb3="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"/>
  <ns-716b5bb3:AccountingCustomerParty xmlns:ns-716b5bb3="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"/>
  <ns-716b5bb3:LegalMonetaryTotal xmlns:ns-716b5bb3="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
    <ns-e4c2ceaa:PayableAmount xmlns:ns-e4c2ceaa="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" currencyID="EUR">15.35</ns-e4c2ceaa:PayableAmount>
  </ns-716b5bb3:LegalMonetaryTotal>
  <ns-716b5bb3:InvoiceLine xmlns:ns-716b5bb3="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
    <ns-e4c2ceaa:ID xmlns:ns-e4c2ceaa="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">PHPUNIT</ns-e4c2ceaa:ID>
    <ns-e4c2ceaa:LineExtensionAmount xmlns:ns-e4c2ceaa="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">555.0</ns-e4c2ceaa:LineExtensionAmount>
    <ns-716b5bb3:Item>
      <ns-e4c2ceaa:Name xmlns:ns-e4c2ceaa="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">PHPUNIT</ns-e4c2ceaa:Name>
    </ns-716b5bb3:Item>
  </ns-716b5bb3:InvoiceLine>
</Invoice>