xsd2php
xsd2php copied to clipboard
naming conflict
First, thank you for your project. helps me a lot.
I have problem while process following xml section:
<xs:complexType name="POCD_MT000040.ObservationMedia">
<xs:sequence>
<xs:element name="realmCode" type="CS" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="typeId" type="POCD_MT000040.InfrastructureRoot.typeId" minOccurs="0"/>
<xs:element name="templateId" type="II" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="id" type="II" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="languageCode" type="CS" minOccurs="0"/>
<xs:element name="value" type="ED"/>
<xs:element name="subject" type="POCD_MT000040.Subject" minOccurs="0"/>
<xs:element name="specimen" type="POCD_MT000040.Specimen" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="performer" type="POCD_MT000040.Performer2" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="author" type="POCD_MT000040.Author" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="informant" type="POCD_MT000040.Informant12" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="participant" type="POCD_MT000040.Participant2" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="entryRelationship" type="POCD_MT000040.EntryRelationship" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="reference" type="POCD_MT000040.Reference" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="precondition" type="POCD_MT000040.Precondition" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="ID" type="xs:ID"/>
<xs:attribute name="nullFlavor" type="NullFlavor" use="optional"/>
<xs:attribute name="classCode" type="ActClassObservation" use="required"/>
<xs:attribute name="moodCode" type="ActMood" use="required"/>
</xs:complexType>
Error:
[Zend\Code\Generator\Exception\InvalidArgumentException]
A method by name getId already exists in this class.
I think ID and attribute conflict with id element. and php are case insensitive, so may be a good way it to naming attritbute to something like idAttr or name id element like idElement.
Actually this is a big issue... the propouse of this project is to create some kind of xsd2php "fancy" mapper... the aim of this project is to hide the XML nature of XSD... this is of course a real use case but adding some prefixes as "attr" will expose the XML nature of underlying data... to be honest I do not know how to deal with this...
Thank you for reply, I have looking into csharp xsd tool and found they simple add number after field... (which is so microsoft: textBox1... label1...)
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="ConfictTest">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
<xs:attribute name="ID" type="xs:string"/>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18063
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System.Xml.Serialization;
//
// This source code was auto-generated by xsd, Version=4.0.30319.17929.
//
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class ConfictTest {
private string idField;
private string nameField;
private string idField1;
private string name1Field;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string id {
get {
return this.idField;
}
set {
this.idField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ID {
get {
return this.idField1;
}
set {
this.idField1 = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("name")]
public string name1 {
get {
return this.name1Field;
}
set {
this.name1Field = value;
}
}
}
Any way, i will modify your code a little for making id -> idElement.
The "microsoft" way is good because in xsd you can have also:
<xs:sequence>
<xs:element name="foo" type="string"/>
<xs:element name="bar" type="int">
</xs:sequence>
</xs:complexType>
This edge case is not handled by this library....
Hi Almir,
I too have encountered this naming conflict between an element and an attribute: the element has a name in the xsd of "TextFormat" and the attribute has a name of "textformat". The error message is "A method by name getTextFormat already exists in this class." So it seems that the letter-case difference in the names is lost in the logic. (The xsd is that of the ONIX standard used by the book publishing industry world-wide -- just in case you were curious.)
I did see your comment about wanting to hide the XML structure from the PHP, but I actually expected attributes to be handled in the PHP classes with "getters" and "setters" like setAttribute($name).
Just my opinion, Rich
probably out of scope for now