I have a number of XML schema that use JAXB (Java Architecture for XML Binding) markup, similar to the following:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="1.0">
<xs:element name="H">
<xs:annotation>
<xs:appinfo>
<jxb:class name="Header" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="X" minOccurs="1" maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<jxb:property name="SessionControl"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="X" type="xs:string">
<xs:annotation>
<xs:appinfo>
<jxb:class name="SessionControl"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:schema>
From these I need to generate C# classes.
Running xsd.exe on the above schema generates the following (some attributes removed for clarity):
[XmlRoot(Namespace = "", IsNullable = false)]
public partial class H
{
private string xField;
public string X
{
get { return this.xField; }
set { this.xField = value; }
}
}
Clearly this is not ideal - I need to take account of the jxb:class
and jxb:property
markup in the schema, giving me a class that uses the more readable jxb
names, but that serializes to the single-character elements/attributes specified in the schema.
e.g.
[XmlRoot(Namespace = "", IsNullable = false, ElementName = "H")]
public partial class Header
{
private string xField;
[XmlElement(ElementName = "X")]
public string SessionControl
{
get { return this.xField; }
set { this.xField = value; }
}
}
Is there any reasonable route to achieving this?