goetas-webservices / xsd2php Goto Github PK
View Code? Open in Web Editor NEWConvert XSD into PHP classes and JMS serializer definitions
License: MIT License
Convert XSD into PHP classes and JMS serializer definitions
License: MIT License
Hi , I got problem when I tried to generate php class from xsd file , the generated files had "AnonymousType" as class name .
How can I prevent this naming rule work ? kept my class name pure
Execute this: "scripts": {
"build": "vendor/bin/xsd2php convert config/test.yml /var/www/igm_client/include/ota/OTA_HotelResRQ.xsd"
}
And the metadata is this:
When I send this requet:
And I have the same issue:
PHP Fatal error: Uncaught exception 'JMS\Serializer\Exception\RuntimeException' with message 'You must define a type for Igm\Synergy\Models\OTA1\HotelResRequestType::$echoToken.' in /var/www/igm_client/vendor/jms/serializer/src/JMS/Serializer/XmlDeserializationVisitor.php:238\nStack trace:\n#0 /var/www/igm_client/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php(267): JMS\Serializer\XmlDeserializationVisitor->visitProperty(Object(JMS\Serializer\Metadata\PropertyMetadata), Object(SimpleXMLElement), Object(JMS\Serializer\DeserializationContext))\n#1 /var/www/igm_client/vendor/jms/serializer/src/JMS/Serializer/Serializer.php(193): JMS\Serializer\GraphNavigator->accept(Object(SimpleXMLElement), Array, Object(JMS\Serializer\DeserializationContext))\n#2 /var/www/igm_client/vendor/jms/serializer/src/JMS/Serializer/Serializer.php(128): JMS\Serializer\Serializer->visit(Object(JMS\Serializer\XmlDeserializationVisitor), Object(JMS\Serializer\DeserializationContext), Object(SimpleXMLElement), 'xml', Array)\n#3 [internal function]: J in /var/www/igm_client/vendor/jms/serializer/src/JMS/Serializer/XmlDeserializationVisitor.php on line 238
But the metadata and class seems it's ok:
What problem I have?
Thanks Asmir.
I'm trying to use xsd2php for OTA 2003/05 / 2014A-1.0.
In addition to #71, there's also a problem with the following definition in OTA_SimpleTypes.xsd
<xs:simpleType name="DateOrTimeOrDateTimeType">
<xs:annotation>
<xs:documentation xml:lang="en">A construct to validate either a date or a time or a dateTime value.</xs:documentation>
</xs:annotation>
<xs:union memberTypes="xs:date xs:dateTime xs:time"/>
</xs:simpleType>
The following valid xml causes an error
<TimeSpan Start="2018-11-12T12:00:00" End="2018-11-13T12:00:00"></TimeSpan>
RuntimeException: Invalid date "2018-11-12T12:00:00", expected valid XML Schema date string.
This is the generated DateTimeSpanType.yml
Hsp\latest\DateTimeSpanType:
properties:
start:
expose: true
access_type: public_method
serialized_name: Start
accessor:
getter: getStart
setter: setStart
xml_attribute: true
type: GoetasWebservices\Xsd\XsdToPhp\XMLSchema\Date
…
Looks as if the yml doesn't contain the other valid types. I guess this is not possible?
Does anyone know a workaround? This is real life XML. I cannot influence the XML and when I tried to modify the xsd to use xs:dateTime
only, it choked on another real life XML that has no time part. I need to handle both cases.
While following the instructions in the README.md
, I had to tweak my config.yml
a bit to get PHP class and YML metadata for JMS Serializer generation working.
Note sure whether this depends on the operating systeem / file system, but it might be good to double check it. I am using macOS Sierra 10.12.1.
breaking: use of slashes
destinations_php
: 'TestNs/MyApp': soap/src
, this results in an error:[GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException]
Can't find a defined location where save 'X\Y\Z\Classname' object
when changing it to 'TestNs\MyApp': soap/src
it works (note that the forward slash has changed to a backward slash.
can be simplified (?): use of quotes
The config.yml
contains single quotes, why is that? When removed it still works?
For example: TestNs\MyApp: soap/src
works as well. Removing all single quotes from my config.yml
breaks nothing...
Whenever I have an element without any attributes that is a list of elements of only 1 type, the generator simplifies this into an array of that nested element. This makes sense, but in some cases I need the list element to be present in the serialized XML, even if it's empty.
An empty array won't be serialized, but an empty element will. I suggest making the "simplifying" of this type of list optional.
I'm not entirely sure how to describe this properly, so let's do it by example.
Given this schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="MainElement">
<xs:sequence>
<xs:element name="ElementList">
<xs:complexType>
<xs:sequence>
<xs:element name="NestedElement" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
The current output would be (simplified):
MainElementType:
properties:
ElementList:
expose: true
access_type: public_method
serialized_name: ElementList
type: array<integer>
xml_list:
inline: false
entry_name: NestedElement
While in some cases I need this to be:
MainElementType:
properties:
ElementList:
expose: true
access_type: public_method
serialized_name: ElementList
type: MainElementType\ElementListAType
The same goes for the generated PHP code. The "ElementListAType" class is already always generated, but MainElement::setElementList()
expects the array, and not the object.
I propose to add a configuration option that enables or disables this "simplifying", with the default still being enabled. I'm already working on a PR for this and will link it shortly.
Hi
I've tried to install Laravel 5.6 today, but composer told me I have to remove xsd2php.
Any idea? Guess it has to do with Symfony 4.
Here's some of the output:
Problem 1
- Conclusion: don't install laravel/framework v5.6.2
- Conclusion: don't install laravel/framework v5.6.1
- Conclusion: don't install laravel/framework v5.6.0
- Conclusion: remove goetas-webservices/xsd2php v0.3.1
- Conclusion: don't install symfony/console v4.0.4
- Conclusion: don't install symfony/console v4.0.3
- Conclusion: don't install symfony/console v4.0.2
- Conclusion: don't install symfony/console v4.0.1
- Conclusion: don't install symfony/console v4.0.0
- Conclusion: don't install symfony/console v4.0.0-RC2
- Conclusion: don't install symfony/console v3.3.16
- Conclusion: don't install symfony/console v4.0.0-RC1
- Conclusion: don't install symfony/console v3.4.0|install symfony/console v4.0.0|install symfony/console v4.0.0-RC1|install symfony/console v4.0.0-RC2|install symfony/console v4.0.1|install symfony/console v4.0.2|install symfony/console v4.0.3|install symfony/console v4.0.4
- Conclusion: don't install symfony/console v3.4.1|install symfony/console v4.0.0|install symfony/console v4.0.0-RC1|install symfony/console v4.0.0-RC2|install symfony/console v4.0.1|install symfony/console v4.0.2|install symfony/console v4.0.3|install symfony/console v4.0.4
- Conclusion: don't install symfony/console v3.4.2|install symfony/console v4.0.0|install symfony/console v4.0.0-RC1|install symfony/console v4.0.0-RC2|install symfony/console v4.0.1|install symfony/console v4.0.2|install symfony/console v4.0.3|install symfony/console v4.0.4
- Conclusion: don't install symfony/console v3.4.3|install symfony/console v4.0.0|install symfony/console v4.0.0-RC1|install symfony/console v4.0.0-RC2|install symfony/console v4.0.1|install symfony/console v4.0.2|install symfony/console v4.0.3|install symfony/console v4.0.4
- Conclusion: don't install symfony/console v3.4.4|install symfony/console v4.0.0|install symfony/console v4.0.0-RC1|install symfony/console v4.0.0-RC2|install symfony/console v4.0.1|install symfony/console v4.0.2|install symfony/console v4.0.3|install symfony/console v4.0.4
- Conclusion: remove symfony/console v3.4.4|install symfony/console v4.0.0|install symfony/console v4.0.0-RC1|install symfony/console v4.0.0-RC2|install symfony/console v4.0.1|install symfony/console v4.0.2|install symfony/console v4.0.3|install symfony/console v4.0.4
- Conclusion: don't install symfony/console v3.3.15
- Conclusion: don't install symfony/console v4.0.0-BETA4
- Conclusion: don't install symfony/console v3.4.0-RC1|install symfony/console v4.0.0|install symfony/console v4.0.0-BETA4|install symfony/console v4.0.0-RC1|install symfony/console v4.0.0-RC2|install symfony/console v4.0.1|install symfony/console v4.0.2|install symfony/console v4.0.3|install symfony/console v4.0.4
- Conclusion: don't install symfony/console v3.4.0-RC2|install symfony/console v4.0.0|install symfony/console v4.0.0-BETA4|install symfony/console v4.0.0-RC1|install symfony/console v4.0.0-RC2|install symfony/console v4.0.1|install symfony/console v4.0.2|install symfony/console v4.0.3|install symfony/console v4.0.4
- Conclusion: don't install symfony/console v3.3.14
- Conclusion: don't install symfony/console v4.0.0-BETA3
- Conclusion: don't install symfony/console v3.3.13
- Conclusion: don't install symfony/console v4.0.0-BETA2
- Conclusion: don't install symfony/console v3.3.12
- Conclusion: don't install symfony/console v4.0.0-BETA1
- Conclusion: don't install symfony/console v3.3.11
- Installation request for laravel/framework 5.6.* -> satisfiable by laravel/framework[5.6.x-dev, v5.6.0, v5.6.1, v5.6.2].
- goetas-webservices/xsd2php v0.3.0 requires symfony/console ^2.7|^3.0 -> satisfiable by symfony/console[v3.4.4, 2.7.x-dev, 2.8.x-dev, 3.0.x-dev, 3.1.x-dev, 3.2.x-dev, 3.3.x-dev, 3.4.x-dev, v2.7.0, v2.7.0-BETA1, v2.7.0-BETA2, v2.7.1, v2.7.10, v2.7.11, v2.7.12, v2.7.13, v2.7.14, v2.7.15, v2.7.16, v2.7.17, v2.7.18, v2.7.19, v2.7.2, v2.7.20, v2.7.21, v2.7.22, v2.7.23, v2.7.24, v2.7.25, v2.7.26, v2.7.27, v2.7.28, v2.7.29, v2.7.3, v2.7.30, v2.7.31, v2.7.32, v2.7.33, v2.7.34, v2.7.35, v2.7.36, v2.7.37, v2.7.38, v2.7.39, v2.7.4, v2.7.40, v2.7.41, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.0-BETA1, v2.8.1, v2.8.10, v2.8.11, v2.8.12, v2.8.13, v2.8.14, v2.8.15, v2.8.16, v2.8.17, v2.8.18, v2.8.19, v2.8.2, v2.8.20, v2.8.21, v2.8.22, v2.8.23, v2.8.24, v2.8.25, v2.8.26, v2.8.27, v2.8.28, v2.8.29, v2.8.3, v2.8.30, v2.8.31, v2.8.32, v2.8.33, v2.8.34, v2.8.4, v2.8.5, v2.8.6, v2.8.7, v2.8.8, v2.8.9, v3.0.0, v3.0.0-BETA1, v3.0.1, v3.0.2, v3.0.3, v3.0.4, v3.0.5, v3.0.6, v3.0.7, v3.0.8, v3.0.9, v3.1.0, v3.1.0-BETA1, v3.1.0-RC1, v3.1.1, v3.1.10, v3.1.2, v3.1.3, v3.1.4, v3.1.5, v3.1.6, v3.1.7, v3.1.8, v3.1.9, v3.2.0, v3.2.0-BETA1, v3.2.0-RC1, v3.2.0-RC2, v3.2.1, v3.2.10, v3.2.11, v3.2.12, v3.2.13, v3.2.14, v3.2.2, v3.2.3, v3.2.4, v3.2.5, v3.2.6, v3.2.7, v3.2.8, v3.2.9, v3.3.0, v3.3.0-BETA1, v3.3.0-RC1, v3.3.1, v3.3.10, v3.3.11, v3.3.12, v3.3.13, v3.3.14, v3.3.15, v3.3.16, v3.3.2, v3.3.3, v3.3.4, v3.3.5, v3.3.6, v3.3.7, v3.3.8, v3.3.9, v3.4.0, v3.4.0-BETA1, v3.4.0-BETA2, v3.4.0-BETA3, v3.4.0-BETA4, v3.4.0-RC1, v3.4.0-RC2, v3.4.1, v3.4.2, v3.4.3].
In the following example only one (the last one in the choice list) ref with property name 'Declaration' is included in BB.yml
input (data is modified/simplified to clearify problem) :
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="urn:tst"
xmlns:ABC_01="BB:ABC:01"
xmlns:DEF_01="BB:DEF:01"
xmlns:GHI_01="BB:GHI:01"
xmlns:AA_01="SW:AA:01"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:tst"
elementFormDefault="qualified">
<xs:import namespace="BB:ABC:01" schemaLocation="BB_ABC_01.xsd"/>
<xs:import namespace="BB:DEF:01" schemaLocation="BB_DEF_01.xsd"/>
<xs:import namespace="BB:GHI:01" schemaLocation="BB_GHI_01.xsd"/>
<xs:import namespace="SW:AA:01" schemaLocation="SW_AA_01.xsd"/>
<xs:element name="BB">
<xs:annotation>
<xs:documentation>
<SW_MessageVersionNumber>00001</SW_MessageVersionNumber>
<SW_MessageVersionDate>1 April 2017</SW_MessageVersionDate>
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="AA_01:MetaData"/>
<xs:element ref="GHI_01:Declaration"/>
<xs:choice>
<xs:element ref="ABC_01:Declaration" minOccurs="0"/>
<xs:element ref="DEF_01:Declaration" minOccurs="0"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
output:
properties:
metaData:
expose: true
access_type: public_method
serialized_name: MetaData
xml_element:
namespace: 'SW:AA:01'
accessor:
getter: getMetaData
setter: setMetaData
type: Test\Test\MetaData
declaration:
expose: true
access_type: public_method
serialized_name: Declaration
xml_element:
namespace: 'BB:DEF:01'
accessor:
getter: getDeclaration
setter: setDeclaration
type: Test\Test\Declaration
Any idea how to solve/fix this?
Thanks!
What about generating class stubs for enummeration simple types and adding enumeration values as constants to the class?
This would help in building the entities as possible values would be available from Code.
Validation of this values is a similar but different issue, though.
<xsd:simpleType name = "GenderType">
<xsd:restriction base = "xsd:string">
<xsd:enumeration value = "Male"/>
<xsd:enumeration value = "Female"/>
</xsd:restriction>
</xsd:simpleType>
class GenderType {
const MALE = 'Male';
const FEMALE = 'Female';
}
Or even maybe add it to the owner class. This would mean a bit of redundancy but the relation from property to SimpleType would be more clear.
class Person {
/** simpleType GenderType*/
const GENDER_MALE = 'Male';
const GENDER_FEMALE = 'Female';
/**
* @property string $gender
*/
private $gender = null;
}
Hi,
We encountered an issue where the yml file created for a entry that is an inline xml_list was giving the namespace of the parent element it was in instead of the elements own namespace.
Attached some example files.
arbetsgivardeklaration.zip
The problem happens in the Skatteverket element of the "http://xmls.skatteverket.se/se/skatteverket/da/instans/schema/1.1" namespace, with the blankett element that belongs to the "http://xmls.skatteverket.se/se/skatteverket/da/komponent/schema/1.1" namespace.
The yml written is
blankett:
xml_list:
inline: true
entry_name: Blankett
namespace: 'http://xmls.skatteverket.se/se/skatteverket/da/instans/schema/1.1'
but for deserialization to work it needs to be
blankett:
xml_list:
inline: true
entry_name: Blankett
namespace: 'http://xmls.skatteverket.se/se/skatteverket/da/komponent/schema/1.1'
In the supplied patch.diff, I change the namespace code to follow the inline:false case instead and that seems to create the right yml for us.
Hi, at first thanks for great tool.
I get a error by deserialize a XML to PHP Object.
Uncaught TypeError: Return value of Doctrine\Common\Annotations\AnnotationRegistry::registerFile() must be an instance of Doctrine\Common\Annotations\void, none returned
this error comes only with this line
$serializer
= $serializerBuilder->build();
what i do wrong?
BuildProcess of PhpClasses and MetaData was succefull...
when you need more Info, let me know.
As discussed in #24, all empty lists are currently skipped during serialization because this is the default (https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/Annotation/XmlCollection.php#L41).
I propose to add the option skip_when_empty
in the YAML to all lists, and setting it to false whenever the element has a minOccurs
of more than 0.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="MainElement">
<xs:sequence>
<xs:element name="RequiredElementList">
<xs:complexType>
<xs:sequence>
<xs:element name="NestedElement" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="OptionalElementList" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="NestedElement" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
Would result in:
MainElementType:
properties:
requiredElementList:
expose: true
access_type: public_method
serialized_name: RequiredElementList
type: array<integer>
xml_list:
inline: false
entry_name: NestedElement
skip_when_empty: false
optionalElementList:
expose: true
access_type: public_method
serialized_name: RequiredElementList
type: array<integer>
xml_list:
inline: false
entry_name: NestedElement
skip_when_empty: true
It would be nice to have list of required elements. minOccurs
Great parser!
This package is really awesome. Tried on some simpler xsd it works perfect. Thank you for your work.
Now trying to use for IATA NDC schemas and it does not work. More about NDC:
http://www.iata.org/whatwedo/airline-distribution/ndc/Pages/default.aspx
Schemas location:
https://github.com/iata-ndc/ndc-xsd-162
Sample xml RQ/RS location:
https://github.com/iata-ndc/ndc-xml-162
Basically you can try deserialize any of sample message and should get error. IATA really big player, and schemas are used by many big systems. So I think is correct.
Can not serialize or deserialize. Fatal error occurs when serializer trying to load generated php class from metadata. I think wrong metadata is generated from xsd.
Added 4 tests. First three tests trying to deserialize sample xml to objects, fourth test trying to serialize created object to xml. Results:
Please see attached files.
My config.yml
xsd2php:
namespaces:
'http://cufxstandards.com/v3/': 'cufx'
destinations_php:
'cufx': 'cufx/src'
destinations_jms:
'cufx': 'cufx/metadata'
naming_strategy: short
path_generator: psr4
xsd2php convert config.yml D:\nginx\html\phoenix\vendor\bin\xsd*.xsd -> Can't load the file
When I try xsd2php convert config.yml D:\nginx\html\phoenix\vendor\bin\xsd\Account.xsd -> Can't find PHP namespace to 'http://cufxstandards.com/v3/Account.xsd' namespace
For something like:
<?php
/**
* Sets a new verifiedName
*
* @param string $verifiedName
* @return self
*/
public function setVerifiedName($verifiedName)
{
$this->verifiedName = $verifiedName;
return $this;
}
Makes sense to use php7 scalar typehints here. Could be hidden behind a flag in config.yml
. I'll try to work on a PR if this sounds helpful?
Even though a nested element may reside in it's own namespace, the parents namespace is still used in the YAML.
Example:
<xs:schema elementFormDefault="qualified" targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://www.example2.com">
<xs:import namespace="http://www.example2.com" schemaLocation="data2.xsd"/>
<xs:complexType name="complexType1">
<xs:sequence>
<xs:element name="ElementList" type="ns2:ElementList"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
The imported schema contains:
<xs:schema elementFormDefault="qualified" targetNamespace="http://www.example2.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="ElementList">
<xs:sequence>
<xs:element maxOccurs="5" name="Element" type="Element"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Element">
<xs:attribute name="attribute" type="xs:string" />
</xs:complexType>
</xs:schema>
Will become:
properties:
ElementList:
...
xml_list:
...
entry_name: Element
namespace: 'http://www.example.com'
...
When it should be:
properties:
ElementList:
...
xml_list:
...
entry_name: Element
namespace: 'http://www.example2.com'
...
I have created a PR in which this should be fixed: #21
Hi,
xs:group not working with my xsd. Is xs:group (https://www.w3schools.com/xml/el_group.asp) not supported?
Thx
I've tried to install xsd2php into a laravel 5.2 framwork. Error message said:
Conclusion: remove symfony/event-dispatcher v3.1.0
I looked into the dependencies, and the wsdl-reader package require symfony/event-dispatcher ^2.2. Laravel already has a symfony/event-dispatcher 3.1.0.
How can I resolve this version issue?
Is there a way to avoid having xsd2php create a file Class.php with class Class {}
when the XSD file has a class element?
I get a syntax error with class Class {}
as class is a reserved keyword.
When I run,
vendor/bin/xsd2php convert config.yml ./xsdrt/maindoc/UBL-Invoice-2.1.xsd
I am getting:
Can't find type named {http://www.w3.org/2000/09/xmldsig#}#base64Binary, at line 49 in /Volumes/Storage/Development/git.macellan.net/mcms/mcms/workbench/macellan/efinans/src/support/xsdrt/common/UBL-xmldsig-core-schema-2.1.xsd
The file UBL-xmldsig-core-schema-2.1.xsd:
<?xml version="1.0" encoding="utf-8"?>
<!--
Library: OASIS Universal Business Language (UBL) 2.1 OS
http://docs.oasis-open.org/ubl/os-UBL-2.1/
Release Date: 04 November 2013
Module: UBL-xmldsig-core-schema-2.1.xsd
Generated on: 2010-08-13 19:10(UTC)
This is a copy of http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd
modified only to remove these PUBLIC and SYSTEM identifiers from the DOCTYPE:
PUBLIC "-//W3C//DTD XMLSchema 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd"
-->
<!DOCTYPE schema
[
<!ATTLIST schema
xmlns:ds CDATA #FIXED "http://www.w3.org/2000/09/xmldsig#">
<!ENTITY dsig 'http://www.w3.org/2000/09/xmldsig#'>
<!ENTITY % p ''>
<!ENTITY % s ''>
]>
<!-- Schema for XML Signatures
http://www.w3.org/2000/09/xmldsig#
$Revision: 1.1 $ on $Date: 2002/02/08 20:32:26 $ by $Author: reagle $
Copyright 2001 The Internet Society and W3C (Massachusetts Institute
of Technology, Institut National de Recherche en Informatique et en
Automatique, Keio University). All Rights Reserved.
http://www.w3.org/Consortium/Legal/
This document is governed by the W3C Software License [1] as described
in the FAQ [2].
[1] http://www.w3.org/Consortium/Legal/copyright-software-19980720
[2] http://www.w3.org/Consortium/Legal/IPR-FAQ-20000620.html#DTD
-->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
targetNamespace="http://www.w3.org/2000/09/xmldsig#"
version="0.1" elementFormDefault="qualified">
<!-- Basic Types Defined for Signatures -->
<simpleType name="CryptoBinary">
<restriction base="base64Binary">
</restriction>
</simpleType>
<!-- Start Signature -->
<element name="Signature" type="ds:SignatureType"/>
<complexType name="SignatureType">
<sequence>
<element ref="ds:SignedInfo"/>
<element ref="ds:SignatureValue"/>
<element ref="ds:KeyInfo" minOccurs="0"/>
<element ref="ds:Object" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="Id" type="ID" use="optional"/>
</complexType>
<element name="SignatureValue" type="ds:SignatureValueType"/>
<complexType name="SignatureValueType">
<simpleContent>
<extension base="base64Binary">
<attribute name="Id" type="ID" use="optional"/>
</extension>
</simpleContent>
</complexType>
<!-- Start SignedInfo -->
<element name="SignedInfo" type="ds:SignedInfoType"/>
<complexType name="SignedInfoType">
<sequence>
<element ref="ds:CanonicalizationMethod"/>
<element ref="ds:SignatureMethod"/>
<element ref="ds:Reference" maxOccurs="unbounded"/>
</sequence>
<attribute name="Id" type="ID" use="optional"/>
</complexType>
<element name="CanonicalizationMethod" type="ds:CanonicalizationMethodType"/>
<complexType name="CanonicalizationMethodType" mixed="true">
<sequence>
<any namespace="##any" minOccurs="0" maxOccurs="unbounded"/>
<!-- (0,unbounded) elements from (1,1) namespace -->
</sequence>
<attribute name="Algorithm" type="anyURI" use="required"/>
</complexType>
<element name="SignatureMethod" type="ds:SignatureMethodType"/>
<complexType name="SignatureMethodType" mixed="true">
<sequence>
<element name="HMACOutputLength" minOccurs="0" type="ds:HMACOutputLengthType"/>
<any namespace="##other" minOccurs="0" maxOccurs="unbounded"/>
<!-- (0,unbounded) elements from (1,1) external namespace -->
</sequence>
<attribute name="Algorithm" type="anyURI" use="required"/>
</complexType>
<!-- Start Reference -->
<element name="Reference" type="ds:ReferenceType"/>
<complexType name="ReferenceType">
<sequence>
<element ref="ds:Transforms" minOccurs="0"/>
<element ref="ds:DigestMethod"/>
<element ref="ds:DigestValue"/>
</sequence>
<attribute name="Id" type="ID" use="optional"/>
<attribute name="URI" type="anyURI" use="optional"/>
<attribute name="Type" type="anyURI" use="optional"/>
</complexType>
<element name="Transforms" type="ds:TransformsType"/>
<complexType name="TransformsType">
<sequence>
<element ref="ds:Transform" maxOccurs="unbounded"/>
</sequence>
</complexType>
<element name="Transform" type="ds:TransformType"/>
<complexType name="TransformType" mixed="true">
<choice minOccurs="0" maxOccurs="unbounded">
<any namespace="##other" processContents="lax"/>
<!-- (1,1) elements from (0,unbounded) namespaces -->
<element name="XPath" type="string"/>
</choice>
<attribute name="Algorithm" type="anyURI" use="required"/>
</complexType>
<!-- End Reference -->
<element name="DigestMethod" type="ds:DigestMethodType"/>
<complexType name="DigestMethodType" mixed="true">
<sequence>
<any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="Algorithm" type="anyURI" use="required"/>
</complexType>
<element name="DigestValue" type="ds:DigestValueType"/>
<simpleType name="DigestValueType">
<restriction base="base64Binary"/>
</simpleType>
<!-- End SignedInfo -->
<!-- Start KeyInfo -->
<element name="KeyInfo" type="ds:KeyInfoType"/>
<complexType name="KeyInfoType" mixed="true">
<choice maxOccurs="unbounded">
<element ref="ds:KeyName"/>
<element ref="ds:KeyValue"/>
<element ref="ds:RetrievalMethod"/>
<element ref="ds:X509Data"/>
<element ref="ds:PGPData"/>
<element ref="ds:SPKIData"/>
<element ref="ds:MgmtData"/>
<any processContents="lax" namespace="##other"/>
<!-- (1,1) elements from (0,unbounded) namespaces -->
</choice>
<attribute name="Id" type="ID" use="optional"/>
</complexType>
<element name="KeyName" type="string"/>
<element name="MgmtData" type="string"/>
<element name="KeyValue" type="ds:KeyValueType"/>
<complexType name="KeyValueType" mixed="true">
<choice>
<element ref="ds:DSAKeyValue"/>
<element ref="ds:RSAKeyValue"/>
<any namespace="##other" processContents="lax"/>
</choice>
</complexType>
<element name="RetrievalMethod" type="ds:RetrievalMethodType"/>
<complexType name="RetrievalMethodType">
<sequence>
<element ref="ds:Transforms" minOccurs="0"/>
</sequence>
<attribute name="URI" type="anyURI"/>
<attribute name="Type" type="anyURI" use="optional"/>
</complexType>
<!-- Start X509Data -->
<element name="X509Data" type="ds:X509DataType"/>
<complexType name="X509DataType">
<sequence maxOccurs="unbounded">
<choice>
<element name="X509IssuerSerial" type="ds:X509IssuerSerialType"/>
<element name="X509SKI" type="base64Binary"/>
<element name="X509SubjectName" type="string"/>
<element name="X509Certificate" type="base64Binary"/>
<element name="X509CRL" type="base64Binary"/>
<any namespace="##other" processContents="lax"/>
</choice>
</sequence>
</complexType>
<complexType name="X509IssuerSerialType">
<sequence>
<element name="X509IssuerName" type="string"/>
<element name="X509SerialNumber" type="integer"/>
</sequence>
</complexType>
<!-- End X509Data -->
<!-- Begin PGPData -->
<element name="PGPData" type="ds:PGPDataType"/>
<complexType name="PGPDataType">
<choice>
<sequence>
<element name="PGPKeyID" type="base64Binary"/>
<element name="PGPKeyPacket" type="base64Binary" minOccurs="0"/>
<any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
</sequence>
<sequence>
<element name="PGPKeyPacket" type="base64Binary"/>
<any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
</sequence>
</choice>
</complexType>
<!-- End PGPData -->
<!-- Begin SPKIData -->
<element name="SPKIData" type="ds:SPKIDataType"/>
<complexType name="SPKIDataType">
<sequence maxOccurs="unbounded">
<element name="SPKISexp" type="base64Binary"/>
<any namespace="##other" processContents="lax" minOccurs="0"/>
</sequence>
</complexType>
<!-- End SPKIData -->
<!-- End KeyInfo -->
<!-- Start Object (Manifest, SignatureProperty) -->
<element name="Object" type="ds:ObjectType"/>
<complexType name="ObjectType" mixed="true">
<sequence minOccurs="0" maxOccurs="unbounded">
<any namespace="##any" processContents="lax"/>
</sequence>
<attribute name="Id" type="ID" use="optional"/>
<attribute name="MimeType" type="string" use="optional"/> <!-- add a grep facet -->
<attribute name="Encoding" type="anyURI" use="optional"/>
</complexType>
<element name="Manifest" type="ds:ManifestType"/>
<complexType name="ManifestType">
<sequence>
<element ref="ds:Reference" maxOccurs="unbounded"/>
</sequence>
<attribute name="Id" type="ID" use="optional"/>
</complexType>
<element name="SignatureProperties" type="ds:SignaturePropertiesType"/>
<complexType name="SignaturePropertiesType">
<sequence>
<element ref="ds:SignatureProperty" maxOccurs="unbounded"/>
</sequence>
<attribute name="Id" type="ID" use="optional"/>
</complexType>
<element name="SignatureProperty" type="ds:SignaturePropertyType"/>
<complexType name="SignaturePropertyType" mixed="true">
<choice maxOccurs="unbounded">
<any namespace="##other" processContents="lax"/>
<!-- (1,1) elements from (1,unbounded) namespaces -->
</choice>
<attribute name="Target" type="anyURI" use="required"/>
<attribute name="Id" type="ID" use="optional"/>
</complexType>
<!-- End Object (Manifest, SignatureProperty) -->
<!-- Start Algorithm Parameters -->
<simpleType name="HMACOutputLengthType">
<restriction base="integer"/>
</simpleType>
<!-- Start KeyValue Element-types -->
<element name="DSAKeyValue" type="ds:DSAKeyValueType"/>
<complexType name="DSAKeyValueType">
<sequence>
<sequence minOccurs="0">
<element name="P" type="ds:CryptoBinary"/>
<element name="Q" type="ds:CryptoBinary"/>
</sequence>
<element name="G" type="ds:CryptoBinary" minOccurs="0"/>
<element name="Y" type="ds:CryptoBinary"/>
<element name="J" type="ds:CryptoBinary" minOccurs="0"/>
<sequence minOccurs="0">
<element name="Seed" type="ds:CryptoBinary"/>
<element name="PgenCounter" type="ds:CryptoBinary"/>
</sequence>
</sequence>
</complexType>
<element name="RSAKeyValue" type="ds:RSAKeyValueType"/>
<complexType name="RSAKeyValueType">
<sequence>
<element name="Modulus" type="ds:CryptoBinary"/>
<element name="Exponent" type="ds:CryptoBinary"/>
</sequence>
</complexType>
<!-- End KeyValue Element-types -->
<!-- End Signature -->
</schema>
Could you allow compatibility with zend-code ^3.0 as that is the default require bundled with ZF 3.0.
While generating metadata files is possible to set namespace prefix to the root element?
e.g:
myXmlElement:
xml_root_name: "ds1:foobar"
xml_root_namespace: "http://www.example"
will turn serialized:
<?xml version="1.0" encoding="UTF-8"?>
<ds1:foobar xmlns:ds1="http://www.example">
</ds1:foobar>
For starters, I apologize for my English. I use translator )
I have an XSD with data types.
The namespace http://zakupki.gov.ru/223fz/types/1 does not meet the PSR to split normally into directories (((
When I try to extract another file! He is requesting this namespace! How to add it to the * .yml file?
For example, the file used with this namespace.
agencyBlockInfo.txt
I sit for a week and can not understand! How to unpack the first and second files! So in a bundle I could create a second file. Thank you in advance.
This issue is related to #38
Updated via composer to version "^0.3".
Generated required data for tests via commands:
vendor/bin/xsd2php convert config.yml xsd/SeatAvailabilityRQ.xsd
vendor/bin/xsd2php convert config.yml xsd/OrderCancelRQ.xsd
vendor/bin/xsd2php convert config.yml xsd/ServiceListRQ.xsd
Rerun same tests. Good news, that issue in #38 is fixed(files exists now). But now got different error. test1.php, test2.php, test3.php:
PHP Fatal error: Uncaught exception 'JMS\Parser\SyntaxErrorException' with message 'Expected T_NAME, but got "" of type T_NONE at beginning of input.' in /home/www/nerijus/goetas/vendor/jms/parser-lib/src/JMS/Parser/AbstractParser.php:118
test4.php after update works now(was not working before).
test2a.php works. Removed xml part from file "test2.php" that was failing.
Pleasee see attached files:
test.zip
I think issue is not fixed properly.
PHP Fatal error: Uncaught exception 'JMS\Parser\SyntaxErrorException' with message 'Expected T_NAME, but got "" of type T_NONE at beginning of input.' in /home/www/nerijus/goetas/vendor/jms/parser-lib/src/JMS/Parser/AbstractParser.php:118
Stack trace:
#0 /home/www/nerijus/goetas/vendor/jms/parser-lib/src/JMS/Parser/AbstractParser.php(73): JMS\Parser\AbstractParser->syntaxError('T_NAME')
#1 /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/TypeParser.php(84): JMS\Parser\AbstractParser->match(1)
#2 /home/www/nerijus/goetas/vendor/jms/parser-lib/src/JMS/Parser/AbstractParser.php(49): JMS\Serializer\TypeParser->parseInternal()
#3 /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/Metadata/PropertyMetadata.php(112): JMS\Parser\AbstractParser->parse('\AnyType')
#4 /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/Metadata/Driver/YamlDriver.php(123): JMS\Serializer\Metadata\PropertyMetadata->setType('\AnyType')
#5 /home/www/nerijus/goetas/vendor/jms/metadata/src/Metadata/Driver/Abstr in /home/www/nerijus/goetas/vendor/jms/parser-lib/src/JMS/Parser/AbstractParser.php on line 118
Fatal error: Uncaught exception 'JMS\Parser\SyntaxErrorException' with message 'Expected T_NAME, but got "" of type T_NONE at beginning of input.' in /home/www/nerijus/goetas/vendor/jms/parser-lib/src/JMS/Parser/AbstractParser.php on line 118
JMS\Parser\SyntaxErrorException: Expected T_NAME, but got "" of type T_NONE at beginning of input. in /home/www/nerijus/goetas/vendor/jms/parser-lib/src/JMS/Parser/AbstractParser.php on line 118
Call Stack:
0.0001 222472 1. {main}() /home/www/nerijus/goetas/test1.php:0
0.2842 2476632 2. JMS\Serializer\Serializer->deserialize() /home/www/nerijus/goetas/test1.php:84
0.3019 2607776 3. PhpOption\Some->map() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/Serializer.php:131
0.3019 2607952 4. call_user_func:{/home/www/nerijus/goetas/vendor/phpoption/phpoption/src/PhpOption/Some.php:89}() /home/www/nerijus/goetas/vendor/phpoption/phpoption/src/PhpOption/Some.php:89
0.3019 2608096 5. JMS\Serializer\Serializer->JMS\Serializer{closure}() /home/www/nerijus/goetas/vendor/phpoption/phpoption/src/PhpOption/Some.php:89
0.3022 2611784 6. JMS\Serializer\Serializer->visit() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/Serializer.php:128
0.3022 2614848 7. JMS\Serializer\GraphNavigator->accept() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/Serializer.php:193
0.6581 4144104 8. JMS\Serializer\XmlDeserializationVisitor->visitProperty() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:266
0.6581 4144280 9. JMS\Serializer\GraphNavigator->accept() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/XmlDeserializationVisitor.php:295
0.6944 4343168 10. JMS\Serializer\XmlDeserializationVisitor->visitProperty() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:266
0.6945 4343392 11. JMS\Serializer\GraphNavigator->accept() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/XmlDeserializationVisitor.php:266
0.6945 4343608 12. JMS\Serializer\XmlDeserializationVisitor->visitArray() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:152
0.6946 4344456 13. JMS\Serializer\GraphNavigator->accept() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/XmlDeserializationVisitor.php:190
0.7565 4569352 14. JMS\Serializer\XmlDeserializationVisitor->visitProperty() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:266
0.7565 4569528 15. JMS\Serializer\GraphNavigator->accept() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/XmlDeserializationVisitor.php:295
0.7565 4569792 16. Metadata\MetadataFactory->getMetadataForClass() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:211
0.7569 4585472 17. Metadata\Driver\DriverChain->loadMetadataForClass() /home/www/nerijus/goetas/vendor/jms/metadata/src/Metadata/MetadataFactory.php:103
0.7569 4585472 18. Metadata\Driver\AbstractFileDriver->loadMetadataForClass() /home/www/nerijus/goetas/vendor/jms/metadata/src/Metadata/Driver/DriverChain.php:38
0.7570 4585608 19. JMS\Serializer\Metadata\Driver\YamlDriver->loadMetadataFromFile() /home/www/nerijus/goetas/vendor/jms/metadata/src/Metadata/Driver/AbstractFileDriver.php:28
0.7628 4608248 20. JMS\Serializer\Metadata\PropertyMetadata->setType() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/Metadata/Driver/YamlDriver.php:123
0.7628 4608248 21. JMS\Parser\AbstractParser->parse() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/Metadata/PropertyMetadata.php:112
0.7628 4609072 22. JMS\Serializer\TypeParser->parseInternal() /home/www/nerijus/goetas/vendor/jms/parser-lib/src/JMS/Parser/AbstractParser.php:49
0.7628 4609120 23. JMS\Parser\AbstractParser->match() /home/www/nerijus/goetas/vendor/jms/serializer/src/JMS/Serializer/TypeParser.php:84
0.7628 4609464 24. JMS\Parser\AbstractParser->syntaxError() /home/www/nerijus/goetas/vendor/jms/parser-lib/src/JMS/Parser/AbstractParser.php:73
Hi, first of all, nice work on this web service!!
It saved me some hours lol.
So, how to auto generate the "@type" JMS\Serializer\Annotation??
Hi,
I am working on a application that needs to generate an xml file. I was given a bunch of xsd files and was able to generate PHP classes using this library but I really don't know what to do next. This the first time I have worked on a project like this so I am a little lost. So after the PHP classes have been generated what is the next step to generate a xml file?
Can anyone please help me out or point me in the right direction?
In case someone wants to see the xsd files I am working with they are located here:
https://www.dropbox.com/sh/i5r6i4zvsaq44o6/AACAHexexdhWo_AbN0VrezqVa?dl=0
I've updated this package and can see:
goetas-webservices/xsd2php v0.3.2
when running composer show
.
Yet, when I look at the composer.json for this package in the vendor folder I can't see the commits for 0.3.2.
Here's part of my composer.json for the 0.3.2 package:
"doctrine/inflector": "^1.0",
"zendframework/zend-code": "~2.3",
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.0",
"jms/serializer": "^1.3",
"goetas-webservices/xsd2php-runtime": "^0.2.7"
},
according to github for this package it should be:
"doctrine/inflector": "^1.0",
"zendframework/zend-code": "^3.0.3",
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.0",
"jms/serializer": "^1.9",
"goetas-webservices/xsd2php-runtime": "^0.2.7",
"ext-xmldiff": "*"
},
What am I doing wrong?
I already removed the vendor folder, cleared the cache and reinstalled everything to no avail.
Thanks!
Fatal error: Uncaught Error: Class 'Symfony\Component\DependencyInjection\ContainerBuilder' not found
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
Hi.
Thank you for the great library.
I'm having trouble with enabling the long naming strategy. As per example, I set the following in config:
naming_strategy: long
And regenerated files. But after this, I ended up with the same files I had before manipulations.
Do I understand correctly, that all my element classes should have Element
suffix and all my types classes should have the Type
suffix after generating when using this naming strategy?
Actually, what forced me to try using the long naming, is that among the generated classes I found the class named My bad, I have not updated to the latest version, where more reversed words were added.PRINT
, which I cannot use as this is a reserved word.
Thank you in advance.
When installing using composer, vendor/bin/ doesn't exist so the command
vendor/bin/xsd2php
doesn't work.
I just managed to convert xsd to classes, but now I am stuck how should I use the classes to convert xml to object. Can you you please add a simple example in docs.
I'm using xsd2php to generate classes for OTA 2003/05 / 2014A-1.0.
Until now, everything went fine. However, there's an issue with a simpleType that is not generated. I tried to alias the type without success.
Class 'Hsp\latest\ListOfRPHType' not found in […]generated/v2014A-1-0/src/ResGuestRPHsType.php on line 11
My configuration:
# see https://github.com/goetas-webservices/xsd2php
xsd2php:
namespaces:
'': 'Hsp\latest'
'http://www.opentravel.org/OTA/2003/05': 'Hsp\latest'
'http://www.opentravel.org/OTA/2003/05/common': 'Hsp\latest'
destinations_php:
'Hsp\latest': generated/v2014A-1-0/src
destinations_jms:
'Hsp\latest': generated/v2014A-1-0/meta
And here's the generated code that causes the problem:
<?php
namespace Hsp\latest;
/**
* Class representing ResGuestRPHsType
*
* A collection of unsigned integers serving as reference placeholders, and used as an index identifying which guests occupy this room
* XSD Type: ResGuestRPHsType
*/
class ResGuestRPHsType extends ListOfRPHType
{
}
ListOfRPH is an xs:simpleType in OTA_SimpleTypes.xsd. ListOfRPHType is not generated and I can't find a way to prevent xsd2php from referencing it.
Can anyone help me with a workaround or solution?
When executing vendor\bin\xsd2php convert config.yml ovu.xsd I get error
"Can't find a PHP namespace to '' namespace".
Attached xsd and yml files. What I do wrong?
Hi, im trying to convert AnyOfferChangedNotification.xsd to PHP but getting the error above.
For converting you will also need: MWSPushNotificationCommon.xsd
my config.yml:
xsd2php:
namespaces:
'http://www.w3.org/2001/XMLSchema': 'Amazon\AnyOfferChange'
destinations_php:
'Amazon\AnyOfferChange': soap/src
destinations_jms:
'Amazon\AnyOfferChange': soap/metadata
naming_strategy: short # optional and default
path_generator: psr4 # optional and default
Comamnd:
vendor/bin/xsd2php convert config.yml xsd/*.xsd
Tbh, i dont really know how to move forward from now on.
`
I got the following XML:
<xs:element name="B2SW">
<xs:annotation>
<xs:documentation>
<SW_MessageVersionNumber>01E01</SW_MessageVersionNumber>
<SW_MessageVersionDate>27 January 2017</SW_MessageVersionDate>
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="MD_01:MetaData"/>
<xs:element ref="MAI_01:Declaration"/>
<xs:choice>
<xs:element ref="ARX_01:Declaration" minOccurs="0"/>
<xs:element ref="ATA_01:Declaration" minOccurs="0"/>
<xs:element ref="ATD_01:Declaration" minOccurs="0"/>
<xs:element ref="CAI_01:Declaration" minOccurs="0"/>
<xs:element ref="COA_01:Declaration" minOccurs="0"/>
<xs:element ref="DIV_01:Declaration" minOccurs="0"/>
<xs:element ref="ENS_01:Declaration" minOccurs="0"/>
<xs:element ref="EXP_01:Declaration" minOccurs="0"/>
<xs:element ref="EXS_01:Declaration" minOccurs="0"/>
<xs:element ref="HZA_01:Declaration" minOccurs="0"/>
<xs:element ref="HZD_01:Declaration" minOccurs="0"/>
<xs:element ref="LCP_01:Declaration" minOccurs="0"/>
<xs:element ref="MFX_01:Declaration" minOccurs="0"/>
<xs:element ref="NOA_01:Declaration" minOccurs="0"/>
<xs:element ref="NOD_01:Declaration" minOccurs="0"/>
<xs:element ref="PAX_01:Declaration" minOccurs="0"/>
<xs:element ref="PRN_01:Declaration" minOccurs="0"/>
<xs:element ref="PRO_01:Declaration" minOccurs="0"/>
<xs:element ref="SDT_01:Declaration" minOccurs="0"/>
<xs:element ref="SEC_01:Declaration" minOccurs="0"/>
<xs:element ref="STO_01:Declaration" minOccurs="0"/>
<xs:element ref="WAS_01:Declaration" minOccurs="0"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
And it creates a new class called B2SW
with setDeclaration(...)
. But it uses the last ref="..."
as type hint and also saves that class to the metadata file. And because of this I got an error that a method does not exists when I try to generate a XML file because not all methods exists in all of those (Declaration
) classes.
Any idea how to fix this?
Hey,
we're using the xsd2php converter to use the generated classes for our SoapClient.
But as it stands, all get* Methods on the objects (which are of the correct type) return null
.
Upon closer inspections the returned objects have their private property set to null
but have an appended public property of the correct type. I think this behaviour comes down to a mismatch in the name of the property and the name attribute of the xsd:element
.
You can see for yourself if you convert the WS-Trust xsd
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
version="1.0">
<xsd:import namespace="http://schemas.xmlsoap.org/ws/2005/02/trust"
schemaLocation="http://schemas.xmlsoap.org/ws/2005/02/trust/WS-Trust.xsd"/>
</xsd:schema>
In the LifetimeType class the private properties are named $created
and $expires
but the name attribute of the corresponding xsd:element
is "Expires" respectively "Created".
I believe this name mismatch originates from the \Doctrine\Common\Inflector\Inflector::camelize
function which gets called in \GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy::getPropertyName.
Would it be possible to use the same name in the generated classes so the SoapClient is able to properly match the properties?
Hello. Big thanx for your work. This lib helped me to save time on genereating tons of xsd based classes, but I've stuck on deserializing - func returns empty objects (objects with null properties).
Can you help with it?
And another question. Is the deserialize procedure smart enough to return all objects given in XML document from the root to the deepest nested or return specific object from (for example) SOAP envelope wich contains many different objects?
Thank you!
not quite correct xml is formed
more info at readme:
https://github.com/Galyam/dhl
I try to convert eppcom-1.0.xsd along with other files for epp version 1 protocol but facing odd problem with simpleType definitions in eppcom.
[GoetasWebservices\XML\XSDReader\Exception\TypeException]
Can't find type named {urn:ietf:params:xml:ns:eppcom-1.0}#clIDType, at line 222 in epp-1.0.xsd
definition in eppcom file exist
<simpleType name="clIDType">
<restriction base="token">
<minLength value="3"/>
<maxLength value="16"/>
</restriction>
</simpleType>
is there any way to map this kind of fields using alias ?
both files app & eppcom attached with extensions added txt
Hi,
I've a question,
When I receive a petition with soap wrap, the serializer extracts them correctly but when I generate a response like:
And serialize the response:
$serializer = $model->getSerializer();
$xmlMessage = $serializer->serialize($response, 'xml');
It not add the soap wrap:
<?xml version="1.0" encoding="UTF-8"?>
<OTA_HotelResRS xmlns="http://www.opentravel.org/OTA/2003/05">
<HotelReservations>
<HotelReservation>
<ResGlobalInfo>
<HotelReservationIDs>
<HotelReservationID ResID_Type="502" ResID_Value="103502"/>
<HotelReservationID ResID_Type="501" ResID_Value="6423533777"/>
</HotelReservationIDs>
</ResGlobalInfo>
</HotelReservation>
</HotelReservations>
</OTA_HotelResRS>
It's possible to add this headers?
Many thanks for advance.
Consider the following XSD:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="TEST_NS" xmlns:tns="TEST_NS"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified">
<xs:complexType name="childType">
<xs:sequence>
<xs:element name="id" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="child" type="tns:childType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
And the JMS generated:
TestSchema\Root:
xml_root_name: root
xml_root_namespace: TEST_NS
properties:
child:
expose: true
access_type: public_method
serialized_name: child
accessor:
getter: getChild
setter: setChild
xml_list:
inline: true
entry_name: child
namespace: TEST_NS
type: array<TestSchema\ChildTypeType>
In this case, the namespace for root/child should be not defined since the local elements are unqualified.
The desired serialization is:
<root xmlns="TEST_NS">
<child xmlns="">
<id>str</id>
</child>
</root>
Instead of:
<root xmlns="TEST_NS">
<child>
<id>str</id>
</child>
</root>
It seems like the YAMLConverter assumes that elementFormDefault="qualified" when resolving namespaces for lists.
I have keysys-1.0.xsd extension file that can't convert.
Error message is
[Zend\Code\Generator\Exception\InvalidArgumentException]
A method by name getForceduplication already exists in this class.
Schema file attached
keysys-1.0.xsd.txt
Hii,
I have a requirement to generate sample XML from XSD files using PHP.I came across this library and followed the initial steps and it worked fine and generated PHP classes and JMS metadata files.But now I am a little bit confused as to how I could generate the XML file (which is I really wanted) using the generated PHP classes and JMS metadata.I am working on Ubuntu 17 OS.My XSD file is given below.
Update: Currently able to generate XML file but type validation note working.Please look at the comment below.
Shipment.xsd
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
<xs:attribute name="maxid" default="xnn" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
The steps I followed is given below.
config.yml
file# config.yml
# Linux Users: PHP Namespaces use back slash \ rather than a forward slash /
# So for destinations_php, the namespace would be TestNs\MyApp
xsd2php:
namespaces:
'': 'TestNs/MyApp'
destinations_php:
'TestNs\MyApp': soap/src
destinations_jms:
'TestNs\MyApp': soap/metadata
aliases: # optional
'':
MyCustomXSDType: 'MyCustomMappedPHPType'
naming_strategy: short # optional and default
path_generator: psr4 # optional and default
vendor/bin/xsd2php convert config.yml files/shipment.xsd
The command run succesfull and I noticed the soap directory was created and inside that there are two subdirectories soap/src
and soap/metadata
.Inside src folder it generated the PHP files and inside metadata folder it generated the yml files.Now how can I create the XML using these generated PHP classes and yml files.
The generated YML-files for the JMS serializer have a invalid format.
The documentation of JMS say, that the file names must have the Formate Vendor.Package.Foo.(xml|yml)
(see http://jmsyst.com/libs/serializer/master/configuration).
Hi guys
I've successfully converted my XSD to metadata & PHP classes in proper namespaces.
My problem is that it seems that XSD2PHP doesn't add the correct namespaces to root elements and child nodes it seems... And therefor is not valid according to the XSD schema
XSD: https://github.com/Skatteetaten/saf-t/blob/master/Norwegian_SAF-T_Cash_Register_Schema_v_1.00.xsd
config.yml
xsd2php:
namespaces:
'urn:StandardAuditFile-Taxation-CashRegister:NO': 'countries\no\saft\xsd2php'
destinations_php:
'countries\no\saft\xsd2php': xsd2php
destinations_jms:
'countries\no\saft\xsd2php': xsd2php/metadata
naming_strategy: 'long'
test.xml - output from xsd2php
<?xml version="1.0" encoding="UTF-8"?>
<result>
<id>1</id>
<header>
<fiscal_year><![CDATA[2018]]></fiscal_year>
</header>
<company>
<company_name><![CDATA[QuickOrder]]></company_name>
<street_address/>
<postal_address/>
<location/>
</company>
</result>
script.php
$AuditFile = new Auditfile();
$HeaderAType = new Auditfile\HeaderAnonymousType();
$HeaderAType->setFiscalYear('2018');
$AuditFile->setHeader(
$HeaderAType
);
$Company = new Auditfile\CompanyAnonymousType();
$Company->setCompanyName('TestCompany');
$AuditFile->setCompany(
$Company
);
$AuditFile->setId(1);
$serializerBuilder = SerializerBuilder::create();
$serializerBuilder->addMetadataDir(APP_PATH . '/common/countries/no/saft/xsd2php/metadata/');
$serializerBuilder->configureHandlers(function (HandlerRegistry $handler) use ($serializerBuilder) {
$serializerBuilder->addDefaultHandlers();
$handler->registerSubscribingHandler(new BaseTypesHandler());
$handler->registerSubscribingHandler(new XmlSchemaDateHandler());
});
$serializer = $serializerBuilder->build();
$newXml = $serializer->serialize($AuditFile, 'xml');
$testFile = __DIR__ . '/../../common/countries/no/saft/examples/test.xml';
if(is_file($testFile)):
unlink($testFile);
endif;
$file = fopen($testFile, "w");
fwrite($file, $newXml);
fclose($file);
$XSDValidator = new XSDValidator();
$XSDValidator->setXMLFile(
__DIR__ . '/../../common/countries/no/saft/examples/test.xml'
)
->setXSDFile(
__DIR__ . '/../../common/countries/no/saft/xsd/Norwegian_SAF-T_Cash_Register_Schema_v_1.00.xsd'
)
->validate();
Is is possible to use the Symfony Serializer rather than JMS?
Hi,
This yml metadata was generated:
Mobile\Search\SearchResult:
xml_root_name: search-result
xml_root_namespace: 'http://services.mobile.de/schema/search'
properties:
total:
expose: true
access_type: public_method
serialized_name: total
xml_element:
namespace: 'http://services.mobile.de/schema/search'
accessor:
getter: getTotal
setter: setTotal
type: integer
pageSize:
expose: true
access_type: public_method
serialized_name: page-size
xml_element:
namespace: 'http://services.mobile.de/schema/search'
accessor:
getter: getPageSize
setter: setPageSize
type: integer
currentPage:
expose: true
access_type: public_method
serialized_name: current-page
xml_element:
namespace: 'http://services.mobile.de/schema/search'
accessor:
getter: getCurrentPage
setter: setCurrentPage
type: integer
maxPages:
expose: true
access_type: public_method
serialized_name: max-pages
xml_element:
namespace: 'http://services.mobile.de/schema/search'
accessor:
getter: getMaxPages
setter: setMaxPages
type: integer
errors:
expose: true
access_type: public_method
serialized_name: errors
xml_element:
namespace: 'http://services.mobile.de/schema/common/error-1.0'
accessor:
getter: getErrors
setter: setErrors
type: array<Mobile\Common\Error\Error>
xml_list:
inline: false
entry_name: error
namespace: 'http://services.mobile.de/schema/search'
ads:
expose: true
access_type: public_method
serialized_name: ads
xml_element:
namespace: 'http://services.mobile.de/schema/search'
accessor:
getter: getAds
setter: setAds
type: array<Mobile\Ad\Ad>
xml_list:
inline: false
entry_name: ad
namespace: 'http://services.mobile.de/schema/search'
I've created the serializer with required handlers:
<?php declare(strict_types = 1);
namespace Mobile\Serializer;
use GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\BaseTypesHandler;
use GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\XmlSchemaDateHandler;
use JMS\Serializer\Handler\HandlerRegistry;
use JMS\Serializer\Serializer;
use JMS\Serializer\SerializerBuilder;
class SerializerFactory
{
private $metaDataDirectory;
private $prefix;
public function __construct(string $metaDataDirectory, string $prefix)
{
$this->metaDataDirectory = $metaDataDirectory;
$this->prefix = $prefix;
}
public function create(): Serializer
{
$serializerBuilder = SerializerBuilder::create();
return $serializerBuilder
->configureHandlers(function (HandlerRegistry $handlerRegistry) use ($serializerBuilder) {
$serializerBuilder->addDefaultHandlers();
$handlerRegistry->registerSubscribingHandler(new BaseTypesHandler());
$handlerRegistry->registerSubscribingHandler(new XmlSchemaDateHandler());
})
->addMetadataDir(
__DIR__.'/../Resources/'.$this->metaDataDirectory, $this->prefix
)
->build()
;
}
}
xsdconfig:
xsd2php:
namespaces:
'http://services.mobile.de/schema/search': 'Mobile\Search'
'http://services.mobile.de/schema/ad': 'Mobile\Ad'
'http://services.mobile.de/schema/resource': 'Mobile\Resource'
'http://services.mobile.de/schema/seller': 'Mobile\Seller'
'http://services.mobile.de/schema/common/financing-1.0': 'Mobile\Common\Financing'
'http://services.mobile.de/schema/common/error-1.0': 'Mobile\Common\Error'
destinations_php:
'Mobile\Search': Search
'Mobile\Ad': Ad
'Mobile\Resource': Resource
'Mobile\Seller': Seller
'Mobile\Common\Financing': Common\Financing
'Mobile\Common\Error': Common\Error
destinations_jms:
'Mobile': Resources/serializer
aliases:
'http://services.mobile.de/schema/ad':
class: 'Mobile\Ad\Clazz'
'http://services.mobile.de/schema/seller':
value: 'string'
naming_strategy: short
path_generator: psr4
If I try to deserialize this response:
I want to deserialize following xml response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<search:search-result xmlns:seller="http://services.mobile.de/schema/seller"
xmlns:ad="http://services.mobile.de/schema/ad"
xmlns:search="http://services.mobile.de/schema/search"
xmlns:financing="http://services.mobile.de/schema/common/financing-1.0"
xmlns:resource="http://services.mobile.de/schema/resource"
xmlns:error="http://services.mobile.de/schema/common/error-1.0">
<search:total>14825</search:total>
<search:page-size>20</search:page-size>
<search:current-page>1</search:current-page>
<search:max-pages>742</search:max-pages>
<search:ads>
<ad:ad key="3" url="https://services.mobile.de/search-api/ad/3">
<ad:creation-date value="2015-12-21T15:47:26+01:00"/>
<ad:modification-date value="2017-01-13T16:15:10+01:00"/>
<ad:detail-page url="http://suchen.mobile.de/auto-inserat/mercedes-benz-200-hamburg/3.html"/>
<!-- [...] -->
</ad:ad>
<!-- [...] -->
My composer.json:
"require": {
"php": "~7.0",
"symfony/options-resolver": "~2.3|~3.0",
"goetas-webservices/xsd2php-runtime":"^0.2.2",
"jms/serializer": "1.5.0-RC1",
"php-http/guzzle6-adapter": "^1.1",
"php-http/mock-client": "^0.3"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"goetas-webservices/xsd2php":"^0.2"
},
latests versions are installed.
The property "ads" of "SearchResult" seems to be empty.
Do you have any ideas to solve my problem ?
you can clone my repository from here https://github.com/robinlehrmann/mobile-de-api to debug it
Thank you very much!
Will this work with cakephp 3 and above
and where is the config.yml to be find
there is one in the tests folder
is that the one to be used
Hello! Your library looks great. Thanks! But iam don't understand how use it. I have this xsd
http://www.opencorpora.org/export/dict/dict.opcorpora.xsd
I want to generate php classes from it.
But I'm only get empty folders.
Please help me. May be you can provide config.yml and cmd example for my schema?
I don't understand how to execute the xsd2php command on Windows.
Any hints?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.