How do I use jaxb bindings to fix multiple group references in a schema?
Part of fpml 5.3 has the following in the schema
<xsd:complexType name="Price">
<xsd:annotation>
<xsd:documentation xml:lang="en">A type describing the strike price.</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="commission" type="Commission" minOccurs="0">
<xsd:annotation>
<xsd:documentation xml:lang="en">This optional component specifies the commission to be charged for executing the hedge transactions.</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:choice minOccurs="0">
<xsd:sequence>
<xsd:element name="determinationMethod" type="DeterminationMethod">
<xsd:annotation>
<xsd:documentation xml:lang="en">Specifies the method according to which an amount or a date is determined.</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:group ref="EquityPrice.model" minOccurs="0"></xsd:group>
</xsd:sequence>
<xsd:element name="amountRelativeTo" type="AmountReference">
<xsd:annotation>
<xsd:documentation xml:lang="en">The href attribute value will be a pointer style reference to the element or component elsewhere in the document where the anchor amount is defined.</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:group ref="EquityPrice.model"></xsd:group>
</xsd:choice>
<xsd:element name="cleanNetPrice" type="xsd:decimal" minOccurs="0">
<xsd:annotation>
<xsd:documentation xml:lang="en">The net price excluding accrued interest. The "Dirty Price" for bonds is put in the "netPrice" element, which includes accrued interest. Thus netPrice - cleanNetPrice = accruedInterest. The currency and price expression for this field are the same as those for the (dirty) netPrice.</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="quotationCharacteristics" type="QuotationCharacteristics" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Allows information about how the price was quoted to be provided.</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
This results in
* <p>
* You are getting this "catch-all" property because of the following reason:
* The field name "GrossPrice" is used by two different parts of a schema. See:
* line 1361 of file:/C:/fpml-jaxb/src/main/xsd/fpml-asset-5-3.xsd
* line 1361 of file:/C:/fpml-jaxb/src/main/xsd/fpml-asset-5-3.xsd
* <p>
The error is misleading. EquityPrice.model starts with this and line 1361 is the grossPrice. The issue stems from above where there are 2 group references to EquityPrice.model in the Price complex type.
<xsd:group name="EquityPrice.model">
<xsd:sequence>
<xsd:element name="grossPrice" type="ActualPrice" minOccurs="0">
<xsd:annotation>
<xsd:documentation xml:lang="en">Specifies the price of the underlyer, before commissions.</xsd:documentation>
</xsd:annotation>
</xsd:element>
The same thing applies for TradeNovationContent where it has multiple references to NewTrade.model.
I also had this same problem, the solution was to enable simple binding mode.
Add the following into your external bindings file.
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
...
<jxb:globalBindings>
<xjc:simple />
</jxb:globalBindings>
Error is caused by the way JAXB is handling groups, as you've seen yourself.
Related
I have the following XSD template for the following:
<xsd:choice>
<xsd:element name="NilReport" type="ftc:CorrectableNilReport_Type">
<xsd:annotation>
<xsd:documentation xml:lang="en">Nil Report indicates that financial institution does not have accounts to report</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:sequence >
<xsd:element name="AccountReport" type="ftc:CorrectableAccountReport_Type" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>Detailed information for account report, such as account number and account balance</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="PoolReport" type="ftc:CorrectablePoolReport_Type" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>Information about the pool of account holders with similar characteristics</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
But the result so far doesn't go as it supposes to be.
Unexpected result
Here is my wanted result:
Expected result
How could i archive the expected result ? Please advice me.
Please note that both and are optional in this case.
Currently your choice lets you pick between the NilReport element and the sequence with the other two elements.
If you want to have the two other elements as children of the "sequence" you will have to create a containing element, and you need to define them as children of that element as follows.
<xsd:choice>
<xsd:element name="NilReport" type="ftc:CorrectableNilReport_Type">
<xsd:annotation>
<xsd:documentation xml:lang="en">Nil Report indicates
that financial institution does not have accounts to report</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="NotNilReport">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="AccountReport" type="ftc:CorrectableAccountReport_Type"
minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>Detailed information for account report, such
as account number and account balance</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="PoolReport" type="ftc:CorrectablePoolReport_Type"
minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>Information about the pool of account holders
with similar characteristics</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:choice>
I am trying to marshall and unmarshal gpx files with an extension. The gpx schema allows to have extension added in the extensions tag example:
<trkpt lat="51.219983" lon="6.765224">
<ele>52.048584</ele>
<time>2009-06-19T10:13:04Z</time>
<extensions>
<gpxdata:hr>164</gpxdata:hr>
<gpxdata:cadence>99</gpxdata:cadence>
</extensions>
</trkpt>
The GPX file is correct and passes unmarshalling like this:
JAXBContext jaxbContext = JAXBContext.newInstance(GpxType.class, com.cluetrust.xml.gpxdata._1._0.ObjectFactory.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
File file = new File("src/test/resources/gpx-example.gpx");
JAXBElement<GpxType> unmarshal = (JAXBElement<GpxType>) unmarshaller.unmarshal(file);
GpxType gpx = unmarshal.getValue();
Two things for me are odd. First off all I have to unmarshal to a JAXBElement and cannot go straight to GpxType, I have to go to the JAXBElement first.
Second of all and that is (for me the biggest problem) once I have the GpxType object. Part is indeed done, but the extensions are not:
ExtensionsType extensions = gpx.getExtensions();
List<Object> extensionsAny = extensions.getAny();
for (Object object : extensionsAny){
System.out.println(object.getClass());
if (object instanceof JAXBElement) {
JAXBElement element = (JAXBElement) object;
LapType lapType = (LapType) element.getValue();
System.out.println(lapType.getStartTime());
}
It seems I have to jump through some hoops here. I have setup a very small project on github where this is shown jaxbproblem. The complete example GPX file i am using is there too. The namespaces in it are correct:
<gpx xmlns="http://www.topografix.com/GPX/1/1"
xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0"
creator="pytrainer http://sourceforge.net/projects/pytrainer" version="1.1">
EDIT:
Relevant part in the schema is :
<xsd:element name="lap" type="lapType">
<xsd:annotation>
<xsd:documentation>
Lap is used to contain information about an individual lap of activity.
Depending upon the device, this may contain a variety of additional information.
Depending upon the device, this may be contained within a run or course.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
and:
<xsd:complexType name="lapType">
<xsd:sequence>
<xsd:element name="index" type="xsd:int" minOccurs="0" maxOccurs="1">
<xsd:annotation><xsd:documentation>The index of the lap in the internal list.</xsd:documentation></xsd:annotation>
</xsd:element>
<xsd:element name="startPoint" type="locationType" minOccurs="0" maxOccurs="1">
<xsd:annotation><xsd:documentation>The starting point of the lap in Lat/Long</xsd:documentation></xsd:annotation>
</xsd:element>
<xsd:element name="endPoint" type="locationType" minOccurs="0" maxOccurs="1">
<xsd:annotation><xsd:documentation>The ending point of the lap in Lat/Long</xsd:documentation></xsd:annotation>
</xsd:element>
<xsd:element name="startTime" type="xsd:dateTime" minOccurs="0" maxOccurs="1">
<xsd:annotation><xsd:documentation>The starting time of the lap</xsd:documentation></xsd:annotation>
</xsd:element>
<xsd:element name="elapsedTime" type="xsd:float" minOccurs="0" maxOccurs="1">
<xsd:annotation><xsd:documentation>The total elapsed time of the lap in seconds</xsd:documentation></xsd:annotation>
</xsd:element>
<xsd:element name="calories" type="xsd:nonNegativeInteger" minOccurs="0" maxOccurs="1">
<xsd:annotation><xsd:documentation>The number of calories burned during the lap</xsd:documentation></xsd:annotation>
</xsd:element>
<xsd:element name="distance" type="xsd:float" minOccurs="0" maxOccurs="1">
<xsd:annotation><xsd:documentation>Distance (in m) covered during the lap</xsd:documentation></xsd:annotation>
</xsd:element>
<xsd:element name="trackReference" type="trackReferenceType" minOccurs="0" maxOccurs="1">
<xsd:annotation><xsd:documentation>Reference information for the track which corresponds to this lap</xsd:documentation></xsd:annotation>
</xsd:element>
<xsd:element name="summary" type="summaryType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation><xsd:documentation>Performance summary elements summarizing different performance measurements, such as cadence, hr, etc.</xsd:documentation></xsd:annotation>
</xsd:element>
<xsd:element name="trigger" type="triggerType" minOccurs="0" maxOccurs="1">
<xsd:annotation><xsd:documentation>The trigger of the lap. On some devices, the lap may be manual or automatic based on attributes known by the device.</xsd:documentation></xsd:annotation>
</xsd:element>
<xsd:element name="intensity" type="intensityKind" minOccurs="0" maxOccurs="1">
<xsd:annotation><xsd:documentation>The intensity of the lap (whether resting or active)</xsd:documentation></xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
This is just one of the many types that are being introduced with this schema that can be found here
What am I doing wrong?
I have a task where I need to create an element "Worker" which has 0 or more subelements "subordinate". I have to use key and keyref to create the references. I can't figure out how make the references "work". Here's what I've written so far:
<xsd:element name="Workers">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Worker" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="subordinate" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="identyfikator" type="PESEL" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:key name="id">
<xsd:selector xpath="Worker"/>
<xsd:field xpath="#identyfikator"/>
</xsd:key>
<xsd:keyref name="subordinate_ref" refer="id">
<xsd:selector xpath="Worker/subordinate"/>
<xsd:field xpath="#identyfikator"/>
</xsd:keyref>
</xsd:element>
PESEL is my own type and the key restriction works well as I am unable to create two workers with the same key in XML document. However, I can create anything as "subordinate" element and no warnings will be displayed. As I understand, in case of such reference I should be only able to add workers as subordinates if they already exist, right? How do I create proper reference?
This is my first time working with XMLSchema so sorry if the code is messy.
Thanks in advance!
Make a Worker ComplexType and have Worker and Subordinate both be of that type.
Approximately like so:
<!-- Define the below where appropriate. -->
<xsd:element name="Worker" type="WorkerType" />
<xsd:complexType name="WorkerType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="subordinate" type="WorkerType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="identyfikator" type="PESEL" use="required"/>
</xsd:complexType>
Also, if you want items to have a unique id, then consider using (or extending) the xsd:ID datatype. This gives you free uniqueness and referential checks using xsd:IDREF.
<xsd:attribute name="identyfikator" type="xsd:ID" use="required"/>
I am working some schema creation.
My schema structure looks like this.
Schema 1(Embedded schema):
It has two fields:
1.select:Drop Down to allow two values "Heading" and "Title"
2.text
Schema 2:
It has following fields;
1.First--of Type Schema 1: As a field. Max occurrence is 4
The source of main schema looks like this:
<xsd:schema elementFormDefault="qualified" xmlns:tcmi="http://www.tridion.com/ContentManager/5.0/Instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.tridion.com/ContentManager/5.0/Instance"></xsd:import>
<xsd:annotation>
<xsd:appinfo>
<tcm:Labels xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
<tcm:Label ElementName="select" Metadata="false">select</tcm:Label>
<tcm:Label ElementName="text" Metadata="false">text</tcm:Label>
</tcm:Labels>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType name="Content">
<xsd:sequence>
<xsd:element name="select" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:appinfo>
<tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
<tcm:Size xmlns:tcm="http://www.tridion.com/ContentManager/5.0">1</tcm:Size>
<tcm:listtype xmlns:tcm="http://www.tridion.com/ContentManager/5.0">select</tcm:listtype>
</xsd:appinfo>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:normalizedString">
<xsd:enumeration value="Heading"></xsd:enumeration>
<xsd:enumeration value="Title"></xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="text" minOccurs="1" maxOccurs="1" type="tcmi:MultiLineText">
<xsd:annotation>
<xsd:appinfo>
<tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
<tcm:Size xmlns:tcm="http://www.tridion.com/ContentManager/5.0">2</tcm:Size>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
This schema is referred in the main schema as "Field"--First
<xsd:schema elementFormDefault="qualified" targetNamespace="some name space" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="some name space" xmlns:tcmi="http://www.tridion.com/ContentManager/5.0/Instance">
<xsd:import namespace="http://www.tridion.com/ContentManager/5.0/Instance" schemaLocation="location.xsd"></xsd:import>
<xsd:include schemaLocation="Schema 1 location"></xsd:include>
<xsd:annotation>
<xsd:appinfo>
<tcm:Labels xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
<tcm:Label ElementName="First" Metadata="false">First</tcm:Label>
</tcm:Labels>
</xsd:appinfo>
</xsd:annotation>
<xsd:element name="Content">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="First" minOccurs="1" maxOccurs="4" type="Content">
<xsd:annotation>
<xsd:appinfo>
<tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
<tcm:EmbeddedSchema xlink:href="Schema 1 location" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xlink:title="abcd"></tcm:EmbeddedSchema>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
The field "First" is following Schema 1. So In turn It has 2 fields.
My need is as No Of occurrence of the Field "First" is 4. I also want to apply one more condition it.
The Conditions:
1.No Of occurrence of the "First" is 4.
2. As Schema 1 has drop down to select values "Heading" and "Title".
I want to restrict that out of 4 occurrence of "First",
Heading can occur Maximum 2 times and Title can occur maximum of 2 two times.
Can any one help how to achieve this.
I have the following requirements and am trying to determine how best to model the XSD to represent these requirements.
I have many instances of an XML element, say <box>. Each <box> has a required attribute t="[box-type]" and each box with a specific type, say t="tall" has another required attribute v="10" which represents the height of the tall box. All <box>es have both t and v attributes, but the restriction on what values are accepted for their v attributes depends on the value of their t attribute.
For example, take the following XML:
<box t="tall" v="10"/>
<box t="named" v="George"/>
<box t="colored" v="green"/>
Now, in my XSD I need to be able represent a sequence of such elements. My thought was to do something like the following which just lists out all of the allowed box types in my sequence (at the end of the following snippet):
<xsd:simpleType name="box_types">
<xsd:restriction base="xsd:token">
<xsd:enumeration value="tall" />
<xsd:enumeration value="named" />
<xsd:enumeration value="colored" />
</xsd:restriction>
</xsd:simpleType>
<!--Box base-->
<xsd:complexType name="box_type">
<xsd:attribute name="t" use="required" type="box_types"/>
<xsd:attribute name="v" use="required"/>
</xsd:complexType>
<!--Box concrete types-->
<xsd:complexType name="tall_box_type">
<xsd:complexContent>
<xsd:extension base="box_type">
<xsd:attribute name="t" fixed="tall" use="required"/>
<xsd:attribute name="v" type="xsd:int" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="named_box_type">
<xsd:complexContent>
<xsd:extension base="box_type">
<xsd:attribute name="t" fixed="named" use="required"/>
<xsd:attribute name="v" type="xsd:string" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="colored_box_type">
<xsd:complexContent>
<xsd:extension base="box_type">
<xsd:attribute name="t" fixed="colored" use="required"/>
<xsd:attribute name="v" type="xsd:token" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<!--And finally, the place where boxes show up-->
<xsd:complexType name="box_usage">
<xsd:sequence>
<xsd:element name="box" type="tall_box_type"/>
<xsd:element name="box" type="named_box_type"/>
<xsd:element name="box" type="colored_box_type"/>
</xsd:sequence>
</xsd:complexType>
Unfortunately, that is not a valid XSD - VS gives me the several errors, the most unfortunate being Elements with the same name and in the same scope must have the same type. Any advice on how I can represent these t/v coupled attribute restrictions in an XSD?
XML Schema 1.0 can't validate dependencies between values. Your options are:
Change your XML. For instance, use tallBox, colorBox and nameBox as element names.
Validate the general structure with XSD and validate values with program logic (or some other tool like Schematron or an XSLT stylesheet).
Use XML Schema 1.1, which can validate value constraints but is not commonly supported, yet.