xsd2php
xsd2php copied to clipboard
Supporting xml_root_prefix
While implementing https://www.bzst.de/DE/Unternehmen/Intern_Informationsaustausch/DAC7/dac7_node.html we need the ability to set the xml_root_prefix config (see https://github.com/schmittjoh/serializer/blob/master/src/Metadata/Driver/YamlDriver.php#L383)
Example:
<?xml version="1.0" encoding="UTF-8"?>
<dip:dip version="1.0" xmlns:dip="http://itzbund.de/ozg/bzst/post/dip/v1/" xmlns:dpi="urn:oecd:ties:dpi:v1" xmlns:iso="urn:oecd:ties:isodpitypes:v1" xmlns:stf="urn:oecd:ties:dpistf:v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://itzbund.de/ozg/bzst/post/dip/v1/ dip.xsd ">
<dip:header environment="TEST">
<dip:consignment>
<dip:customerIdentifier>
<dip:identityProvider>BZST-CERT</dip:identityProvider>
<dip:identifier>BZ123456789</dip:identifier>
</dip:customerIdentifier>
<dip:creationTime>2023-10-01T12:00:00</dip:creationTime>
<dip:transferticketId>09dedc8e-d2f8-4293-ad9e-9b50abce961c</dip:transferticketId>
</dip:consignment>
<dip:application code="DAC7"/>
</dip:header>
<dip:body>
<dip:consignmentItem>
<dip:data>
<dpi:DPI_OECD version="1.0" xsi:schemaLocation="urn:oecd:ties:dpi:v1 DPIXML_v1.0.xsd " />
</dip:data>
</dip:consignmentItem>
</dip:body>
</dip:dip>
Why a specific prefix is important? If the namespace for a generated prefix is correct, any "good" xml parser should work well with it
The lib haven't generated a prefix at all yet.
xmlns:dip="http://itzbund.de/ozg/bzst/post/dip/v1/" doesn't result in dip: or xmlns:dpi="urn:oecd:ties:dpi:v1" doesn't in dpi:.
I try to match an example xml provided by the xsd author in a test and the prefixes are present. So I thought they are mandatory, aren't they?
Could you please provide the expected xml and the currently generated one?
On Fri, Feb 14, 2025, 08:50 David Pommer @.***> wrote:
The lib haven't generated a prefix at all yet.
xmlns:dip="http://itzbund.de/ozg/bzst/post/dip/v1/" doesn't result in dip: or xmlns:dpi="urn:oecd:ties:dpi:v1" doesn't in dpi:.
I try to match an example xml provided by the xsd author in a test and the prefixes are present. So I thought they are mandatory, aren't they?
— Reply to this email directly, view it on GitHub https://github.com/goetas-webservices/xsd2php/issues/182#issuecomment-2658514232, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAF5UJZ5XCLHY7S3TMKJROL2PWN5PAVCNFSM6AAAAABW2YB6Q6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNJYGUYTIMRTGI . You are receiving this because you commented.Message ID: @.***> [image: dyron]dyron left a comment (goetas-webservices/xsd2php#182) https://github.com/goetas-webservices/xsd2php/issues/182#issuecomment-2658514232
The lib haven't generated a prefix at all yet.
xmlns:dip="http://itzbund.de/ozg/bzst/post/dip/v1/" doesn't result in dip: or xmlns:dpi="urn:oecd:ties:dpi:v1" doesn't in dpi:.
I try to match an example xml provided by the xsd author in a test and the prefixes are present. So I thought they are mandatory, aren't they?
— Reply to this email directly, view it on GitHub https://github.com/goetas-webservices/xsd2php/issues/182#issuecomment-2658514232, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAF5UJZ5XCLHY7S3TMKJROL2PWN5PAVCNFSM6AAAAABW2YB6Q6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNJYGUYTIMRTGI . You are receiving this because you commented.Message ID: @.***>
Expected xml:
<?xml version="1.0" encoding="UTF-8"?>
<dip:dip version="1.0" xmlns:dip="http://itzbund.de/ozg/bzst/post/dip/v1/" xmlns:dpi="urn:oecd:ties:dpi:v1" xmlns:iso="urn:oecd:ties:isodpitypes:v1" xmlns:stf="urn:oecd:ties:dpistf:v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://itzbund.de/ozg/bzst/post/dip/v1/ dip.xsd ">
<dip:header environment="TEST">
<dip:consignment>
<dip:customerIdentifier>
<dip:identityProvider>BZST-CERT</dip:identityProvider>
<dip:identifier>BZ123456789</dip:identifier>
</dip:customerIdentifier>
<dip:creationTime>2023-10-01T12:00:00</dip:creationTime>
<dip:transferticketId>09dedc8e-d2f8-4293-ad9e-9b50abce961c</dip:transferticketId>
</dip:consignment>
<dip:application code="DAC7"/>
</dip:header>
<dip:body>
<dip:consignmentItem>
<dip:data>
<dpi:DPI_OECD version="1.0" xsi:schemaLocation="urn:oecd:ties:dpi:v1 DPIXML_v1.0.xsd ">
<dpi:MessageSpec>
<dpi:SendingEntityIN>1234567891011</dpi:SendingEntityIN>
<dpi:TransmittingCountry>DE</dpi:TransmittingCountry>
<dpi:ReceivingCountry>DE</dpi:ReceivingCountry>
<dpi:MessageType>DPI</dpi:MessageType>
<dpi:MessageRefId>DE2023DE-c0d5e394-e264-4dc7-9e51-c57b6a638ae5
</dpi:MessageRefId>
<dpi:MessageTypeIndic>DPI401</dpi:MessageTypeIndic>
<dpi:ReportingPeriod>2023-12-31</dpi:ReportingPeriod>
<dpi:Timestamp>2022-12-15T09:45:30</dpi:Timestamp>
</dpi:MessageSpec>
<dpi:DPIBody>
<dpi:PlatformOperator>
<dpi:ResCountryCode>DE</dpi:ResCountryCode>
<dpi:TIN issuedBy="DE">1234567891011
</dpi:TIN>
<dpi:Name>Plattformbetreiber GmbH</dpi:Name>
<dpi:PlatformBusinessName>Testplattform</dpi:PlatformBusinessName>
<dpi:Address legalAddressType="OECD304">
<dpi:CountryCode>DE</dpi:CountryCode>
<dpi:AddressFix>
<dpi:Street>Plattformbetreiberstraße</dpi:Street>
<dpi:BuildingIdentifier>2</dpi:BuildingIdentifier>
<dpi:PostCode>12345</dpi:PostCode>
<dpi:City>Plattformbetreiberstadt</dpi:City>
</dpi:AddressFix>
</dpi:Address>
<dpi:Nexus>RPONEX1</dpi:Nexus>
<dpi:AssumedReporting>false</dpi:AssumedReporting>
<dpi:DocSpec>
<stf:DocTypeIndic>OECD1</stf:DocTypeIndic>
<stf:DocRefId>DE2023-d5c4c49b-79bc-4b22-a6cd-3f45cfd801f3</stf:DocRefId>
</dpi:DocSpec>
</dpi:PlatformOperator>
</dpi:DPIBody>
</dpi:DPI_OECD>
</dip:data>
</dip:consignmentItem>
</dip:body>
</dip:dip>
Actual
<?xml version="1.0" encoding="UTF-8"?>
<dip xmlns="http://itzbund.de/ozg/bzst/post/dip/v1/" version="1.0">
<header environment="TEST">
<consignment>
<customerIdentifier>
<identityProvider>BZST-CERT</identityProvider>
<identifier>BZ123456789</identifier>
</customerIdentifier>
<creationTime>2023-10-01T12:00:00</creationTime>
<transferticketId>09dedc8e-d2f8-4293-ad9e-9b50abce961c</transferticketId>
</consignment>
<application code="DAC7"/>
</header>
<body>
<consignmentItem>
<data version="1.0">
<ns-0648b7ac:MessageSpec xmlns:ns-0648b7ac="urn:oecd:ties:dpi:v1">
<ns-0648b7ac:SendingEntityIN>1234567891011</ns-0648b7ac:SendingEntityIN>
<ns-0648b7ac:TransmittingCountry>DE</ns-0648b7ac:TransmittingCountry>
<ns-0648b7ac:ReceivingCountry>DE</ns-0648b7ac:ReceivingCountry>
<ns-0648b7ac:MessageType>DPI</ns-0648b7ac:MessageType>
<ns-0648b7ac:MessageRefId>DE2023DE-c0d5e394-e264-4dc7-9e51-c57b6a638ae5</ns-0648b7ac:MessageRefId>
<ns-0648b7ac:MessageTypeIndic>DPI401</ns-0648b7ac:MessageTypeIndic>
<ns-0648b7ac:ReportingPeriod>2023-12-31</ns-0648b7ac:ReportingPeriod>
<ns-0648b7ac:Timestamp>2022-12-15T09:45:30</ns-0648b7ac:Timestamp>
</ns-0648b7ac:MessageSpec>
<ns-0648b7ac:DPIBody xmlns:ns-0648b7ac="urn:oecd:ties:dpi:v1">
<ns-0648b7ac:PlatformOperator>
<ns-0648b7ac:ResCountryCode>DE</ns-0648b7ac:ResCountryCode>
<ns-0648b7ac:TIN issuedBy="DE">1234567891011</ns-0648b7ac:TIN>
<ns-0648b7ac:Name>Plattformbetreiber GmbH</ns-0648b7ac:Name>
<ns-0648b7ac:PlatformBusinessName>Testplattform</ns-0648b7ac:PlatformBusinessName>
<ns-0648b7ac:Address>
<ns-0648b7ac:CountryCode>DE</ns-0648b7ac:CountryCode>
<ns-0648b7ac:AddressFix>
<ns-0648b7ac:Street>Plattformbetreiberstraße</ns-0648b7ac:Street>
<ns-0648b7ac:BuildingIdentifier>2</ns-0648b7ac:BuildingIdentifier>
<ns-0648b7ac:PostCode>12345</ns-0648b7ac:PostCode>
<ns-0648b7ac:City>Plattformbetreiberstadt</ns-0648b7ac:City>
</ns-0648b7ac:AddressFix>
</ns-0648b7ac:Address>
<ns-0648b7ac:Nexus>RPONEX1</ns-0648b7ac:Nexus>
<ns-0648b7ac:AssumedReporting>false</ns-0648b7ac:AssumedReporting>
<ns-0648b7ac:DocSpec>
<ns-cb0da4ea:DocTypeIndic xmlns:ns-cb0da4ea="urn:oecd:ties:dpistf:v1">OECD1</ns-cb0da4ea:DocTypeIndic>
<ns-cb0da4ea:DocRefId xmlns:ns-cb0da4ea="urn:oecd:ties:dpistf:v1">DE2023-d5c4c49b-79bc-4b22-a6cd-3f45cfd801f3</ns-cb0da4ea:DocRefId>
</ns-0648b7ac:DocSpec>
</ns-0648b7ac:PlatformOperator>
</ns-0648b7ac:DPIBody>
</data>
</consignmentItem>
</body>
</dip>
Current config.yml
xsd2php:
namespaces:
'http://itzbund.de/ozg/bzst/post/dip/v1/': 'My\Namespace\Dip'
'urn:oecd:ties:dpi:v1': 'My\Namespace\DAC7'
'urn:oecd:ties:dpistf:v1': 'My\Namespace\DAC7\Types\Oecd'
'urn:oecd:ties:isodpitypes:v1': 'My\Namespace\DAC7\Types\Iso'
destinations_php:
'My\Namespace': src
destinations_jms:
'My\Namespace': metadata
known_locations: # optional
'http://itzbund.de/ozg/bzst/post/dip/v1/': xsd/dip.xsd
known_namespace_locations: # optional
'urn:oecd:ties:dpi:v1': 'xsd/DAC7/DPI7DPIXML_v1.08.xsd'
'urn:oecd:ties:dpistf:v1': xsd/DAC7/oecddpitypes_v1.0.xsd
'urn:oecd:ties:isodpitypes:v1': xsd/DAC7/isodpitypes_v1.0.xsd
configs_jms: #optional
xml_cdata: false # Disables CDATA
aliases: # optional
'http://www.w3.org/2001/XMLSchema':
anyType: 'My\Namespace\UserDataHandler'
Both document semantically are the same.
<dip xmlns="http://itzbund.de/ozg/bzst/post/dip/v1/" version="1.0"> and <dip:dip xmlns:dip="http://itzbund.de/ozg/bzst/post/dip/v1/" version="1.0"> are exactly the same thing.
https://3v4l.org/OkNIs
Are you sure the "other part" has a decent xml implementation?
Are you sure the "other part" has a decent xml implementation?
No, but I'll give it a try. Since it's a government institution I expect to match the provided example.
The receiving part expexts the root prefix.
Follow-up:
For anybody interested in how I finally was able to generate the expected xml.
I had to make manual additions for xml_namespaces and the xsi: properties to the metadata yml files:
My\Namespace\Dip:
xml_root_name: dip
xml_root_namespace: 'http://itzbund.de/ozg/bzst/post/dip/v1/'
xml_root_prefix: dip
xml_namespaces:
dpi: 'urn:oecd:ties:dpi:v1'
iso: urn:oecd:ties:isodpitypes:v1
stf: urn:oecd:ties:dpistf:v1
xsi: http://www.w3.org/2001/XMLSchema-instance
My\Namespace\DAC7\DPIOECD:
xml_root_name: DPI_OECD
xml_root_namespace: 'urn:oecd:ties:dpi:v1'
xml_root_prefix: dpi
xml_namespaces:
stf: urn:oecd:ties:dpistf:v1
xsi: http://www.w3.org/2001/XMLSchema-instance
The schemaLocation attributes are also added manually:
<?php
namespace My\Namespace\Dip;
class Dip
{
private $schemaLocation = 'http://itzbund.de/ozg/bzst/post/dip/v1/ dip.xsd ';
My\Namespace\Dip:
properties:
schemaLocation:
serialized_name: schemaLocation
xml_attribute: true
xml_element:
namespace: 'http://www.w3.org/2001/XMLSchema-instance'