How to access jaxb:class element - xsd

How do I get the jaxb:class element to show? I currently have the following xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:version="2.0" jaxb:extensionBindingPrefixes="xjc"
elementFormDefault="qualified" targetNamespace="***"
xmlns:common="***">
<xs:complexType name="IdentifiableDTO" abstract="true">
<xs:annotation>
<xs:appinfo></xs:appinfo>
</xs:annotation>
<xs:attribute name="id" type="common:uuid" />
</xs:complexType>
</xs:schema>
But the only elements I can access within the xs:appinfo is jaxb:globalBindings and jaxb:javaType. I need to specify the jaxb:class so I can add some custom behaviour.

What is exactly the problem with:
<xs:complexType name="IdentifiableDTO">
<xs:annotation>
<xs:appinfo>
<jaxb:class name="MySpecificIdentifiableDTOClassName"/>
</xs:appinfo>
</xs:annotation>
<!-- ... -->
</xs:complexType>
What do you mean by "get the jaxb:class element to show?"

Related

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found

I am trying to understand <any> element in xsd. I had two xsds.
Book Catalogue.xsd
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="BookCatalogue">
<xs:complexType>
<xs:sequence>
<xs:element name="Book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string" />
<xs:element name="Author" type="xs:string" />
<xs:element name="Date" type="xs:string" />
<xs:element name="ISBN" type="xs:string" />
<xs:element name="Publisher" type="xs:string" />
<xs:any namespace="##any" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Reviewer.xsd
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="Reviewer">
<xs:complexType>
<xs:sequence>
<xs:element name="Name">
<xs:complexType>
<xs:sequence>
<xs:element name="First" type="xs:string" />
<xs:element name="Last" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
But if i validate the below xml based on above xsd, i am getting cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'p:Reviewer'. error. Does both xsd file should not be in same namespace?
<?xml version="1.0" encoding="UTF-8"?>
<pr:BookCatalogue xmlns:pr="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com AddRequest.xsd ">
<pr:Book>
<pr:Title>pr:Title</pr:Title>
<pr:Author>pr:Author</pr:Author>
<pr:Date>pr:Date</pr:Date>
<pr:ISBN>pr:ISBN</pr:ISBN>
<pr:Publisher>pr:Publisher</pr:Publisher>
<p:Reviewer xmlns:p="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com Children.xsd ">
<p:Name>
<p:First>p:First</p:First>
<p:Last>p:Last</p:Last>
</p:Name>
</p:Reviewer>
</pr:Book>
</pr:BookCatalogue>
Two options...
Option One: If you do not want to have to have the definition of p:Reviewer present, add processContents="lax" to your xs:any element:
<xs:any namespace="##any" minOccurs="0" processContents="lax"/>
Per XML Schema Part 0: Primer Second Edition:
The lax value of the processContents attribute instructs an XML
processor to validate the element content on a can-do basis: It will
validate elements and attributes for which it can obtain schema
information, but it will not signal errors for those it cannot obtain
any schema information.
See also XML Validation in Java: processContents=“lax” seems not to work correctly.
You should also carefully adjust your xsi:schemaLocation values to point to the actual filename of each XSD for each namespace in play. Here is your XML instance with the changes that I made:
<?xml version="1.0" encoding="UTF-8"?>
<pr:BookCatalogue
xmlns:pr="http://www.w3schools.com"
xmlns:p="http://www.w3schools.com/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com BookCatalogue.xsd http://www.w3schools.com/1 Reviewer.xsd">
<pr:Book>
<pr:Title>pr:Title</pr:Title>
<pr:Author>pr:Author</pr:Author>
<pr:Date>pr:Date</pr:Date>
<pr:ISBN>pr:ISBN</pr:ISBN>
<pr:Publisher>pr:Publisher</pr:Publisher>
<p:Reviewer>
<p:Name>
<p:First>p:First</p:First>
<p:Last>p:Last</p:Last>
</p:Name>
</p:Reviewer>
</pr:Book>
</pr:BookCatalogue>
Note: Make sure that the targetNamespace in Review.xsd matches what's declared for it in BookCatalogue.xml's xsi:schemaLocation attribute.
Option Two: If you do want to insist that the definition of p:Reviewer be present, just make the above changes to be sure that Review.xsd can be found per the xsi:schemaLocation mechanism. No processContents setting is required; it defaults to strict.

JAXB Simplify plugin vs *.xjb

I'm trying to use the Simplify plugin to replace a complex property with a set of simpler ones. I made it working following the plugin's manual. But I can't change the original schema, so I have to use an external bindings.xjb. And it gives me all sort of errors. Does somebody have a working example of a similar thing?
Original XSD:
<xs:schema id="messages"
elementFormDefault="qualified"
version="Exchange2010_SP2"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:tns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.microsoft.com/exchange/services/2006/messages">
<xs:import namespace="http://schemas.microsoft.com/exchange/services/2006/types" schemaLocation="types.xsd"/>
...
<xs:complexType name="ArrayOfResponseMessagesType">
<xs:choice maxOccurs="unbounded">
<xs:element name="CreateItemResponseMessage" type="m:ItemInfoResponseMessageType"/>
<xs:element name="DeleteItemResponseMessage" type="m:ResponseMessageType"/>
<xs:element name="GetItemResponseMessage" type="m:ItemInfoResponseMessageType"/>
...
</xs:choice>
</xs:complexType>
Modified XSD that works for me:
<xs:schema id="messages"
elementFormDefault="qualified"
version="Exchange2010_SP2"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:tns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:extensionBindingPrefixes="simplify"
targetNamespace="http://schemas.microsoft.com/exchange/services/2006/messages">
<xs:import namespace="http://schemas.microsoft.com/exchange/services/2006/types" schemaLocation="types.xsd"/>
...
<xs:complexType name="ArrayOfResponseMessagesType">
<xs:choice maxOccurs="unbounded">
<xs:element name="CreateItemResponseMessage" type="m:ItemInfoResponseMessageType">
<xs:annotation>
<xs:appinfo>
<simplify:as-element-property/>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="DeleteItemResponseMessage" type="m:ResponseMessageType"/>
<xs:element name="GetItemResponseMessage" type="m:ItemInfoResponseMessageType"/>
...
</xs:choice>
</xs:complexType>
My bindings.xjb (that I want to use instead of changing the schema):
<bindings version="2.1"
xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
extensionBindingPrefixes="simplify">
<bindings schemaLocation="../wsdl/messages.xsd" node="/xs:schema/xs:complexType[#name='ArrayOfResponseMessagesType']/xs:choice/xs:element[1]">
<xs:annotation>
<xs:appinfo>
<simplify:as-element-property/>
</xs:appinfo>
</xs:annotation>
</bindings>
</bindings>
My current exception
org.xml.sax.SAXParseException: Unsupported binding namespace "http://www.w3.org/2001/XMLSchema". Perhaps you meant "http://java.sun.com/xml/ns/jaxb/xjc"?
Ok, I figured this out. Here is the configuration that made it working:
<bindings version="2.1"
xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
extensionBindingPrefixes="simplify">
<bindings schemaLocation="../wsdl/messages.xsd" node="/xs:schema/xs:complexType[#name='ArrayOfResponseMessagesType']/xs:choice/xs:element[1]">
<simplify:as-element-property/>
</bindings>
</bindings>
That simple.

XSD extend a complex type

I'm trying to extend an existing complextype in a XSD file.
I have created a new xsd file and included it at the end of all the master XSD files includes.
The problem I'm having is that it seems to add my extension but it removes the existing elements other than those defined in asset_abstract
Is what I'm trying to do possible?
Code I don't want to modify
<xs:complexType name="Feature_Cadastre_Lot" abstract="false">
<xs:annotation>
<xs:documentation>Represents the boundary of a titled, or proposed lot</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="asset_abstract">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="LotNo" type="String_32" minOccurs="1" maxOccurs="1" nillable="false">
<xs:annotation>
<xs:documentation>The lot number as described on the originating survey plan</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="PlanNo" type="String_32" minOccurs="1" maxOccurs="1" nillable="false">
<xs:annotation>
<xs:documentation>The plan number of the originating survey plan.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="CancelledLotPlan" type="String_32" minOccurs="1" maxOccurs="1" nillable="true">
<xs:annotation>
<xs:documentation>The lot on plan cancelled by this boundary if applicable.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="TitledArea_sqm" type="Float_Positive_NonZero" minOccurs="1" maxOccurs="1" nillable="false">
<xs:annotation>
<xs:documentation>The area in square metres enclosed by the boundary, as described by the survey plan.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="Geometry" type="geometry_area_multipatch_simple" minOccurs="1" maxOccurs="1" nillable="false">
<xs:annotation>
<xs:documentation>The geometry of this feature in coordinate space. May contain holes and islands. Boundaries must consist of straight lines.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
Code I can import to extend the scheme.
<xs:complexType name="Feature_Cadastre_Lot">
<xs:complexContent>
<xs:extension base="asset_abstract">
<xs:sequence>
<xs:element name="LMS_ID_1" type="String_32" minOccurs="1" maxOccurs="1" nillable="false">
<xs:annotation>
<xs:documentation>The Land Management System ID as defined by the LMS Team</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="LMS_ID_2" type="String_32" minOccurs="1" maxOccurs="1" nillable="false">
<xs:annotation>
<xs:documentation>The Land Management System ID as defined by the LMS Team</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
OK I've created a bare bones exmaple and I still can't get it to work now using visual studio as I wanna make sure its not the tool :) , I still can't get it too work as yours is :( I must be missing something.
Basically I've added 2 files Master.xsd and local.xsd
Master wraps the remote project I can't / don't want to modify direct and local.xsd is where all our site specific stuff (redefining as it is called).
Master.xsd
<?xml version="1.0"?>
<xs:schema version="1.0.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="project.xsd">
</xs:include>
<xs:include schemaLocation="local.xsd">
<xs:annotation>
<xs:documentation>A File I can add my overwrites to</xs:documentation>
</xs:annotation>
</xs:include>
</xs:schema>
project.xsd
<?xml version="1.0"?>
<xs:schema version="1.0.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="remote.xsd">
<xs:annotation>
<xs:documentation>A File that contains the complexType I want to add elments to. But not modify otherwise</xs:documentation>
</xs:annotation>
</xs:include>
<xs:element name="Master_Project">
<xs:annotation>
<xs:documentation>The Project.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="ProjectData">
<xs:complexType>
<xs:sequence>
<xs:element name="ExistingElement" type="ExistingElementType">
<xs:annotation>
<xs:documentation>An Existing Element That I would Like To Add To.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
local.xsd
<?xml version="1.0"?>
<xs:schema version="1.0.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:redefine schemaLocation="./remote.xsd">
<xs:complexType name="ExistingElementType">
<xs:complexContent>
<xs:extension base="ExistingElementType">
<xs:sequence>
<xs:element name="newTest"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
</xs:schema>
remote.xsd
<?xml version="1.0"?>
<xs:schema version="1.0.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="ExistingElementType">
<xs:sequence>
<xs:element name="someProperty"/>
<xs:element name="someSecondProperty"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
And where I do all the redefining eventually.
If you want to keep the name of the complex type as "Feature_Cadastre_Lot" and extend it with additional content, then you are looking at redefine instead. The net effect is that all references to "Feature_Cadastre_Lot", preexisting and new, will include the newly added content.
If you want this in some, but not all of the existing content, there is no solution to it (redefine is all or nothing).
The redefine has the following layout:
<xs:redefine schemaLocation="must resolve to your XSD">
<xs:complexType name="Feature_Cadastre_Lot">
<xs:complexContent>
<xs:extension base="Feature_Cadastre_Lot">
<xs:sequence>
<xs:element name="LMS_ID_1" type="String_32" minOccurs="1" maxOccurs="1" nillable="false">
<xs:annotation>
<xs:documentation>The Land Management System ID as defined by the LMS Team</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="LMS_ID_2" type="String_32" minOccurs="1" maxOccurs="1" nillable="false">
<xs:annotation>
<xs:documentation>The Land Management System ID as defined by the LMS Team</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
The result will look like this:
You can see the highlighted sequence as showing the added content.
In Visual Studio 2010, the content also shows ok:
Notice the second sequence at the bottom.

Including / importing local schemas that have namespaces

Here is a schema file, midi.xsd that defines a type, note, used to store MIDI note values:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="note">
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="127"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Here is another schema file, octaves.xsd which uses midi.xsd to help define the layout to be enforced on an XML file containing data about octaves:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="midi.xsd"/>
<xs:element name="octaves">
<xs:complexType>
<xs:sequence>
<xs:element name="octave">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="midi">
<xs:complexType>
<xs:sequence>
<xs:element name="value" type="xs:integer" />
<xs:element name="from" type="note" />
<xs:element name="to" type="note" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="index" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This is fine, and works exactly as you would expect it to, except that I have another requirement: I want note to be in its own namespace, midi, so that
<xs:element name="from" type="note" />
becomes
<xs:element name="from" type="midi:note" />
Try as I might, I cannot get this to work. My attempts have included use of the targetNamespace attribute in various places, the import element, and liberal use of xmlns:midi="...", but to no avail. I'd post one of these attempts here, were it not so cringe-worthy.
Could some kind soul point me in the right direction? I'm pretty sure the problem is to do with the fact that midi.xsd is a local file; it has never been, and never will be, hosted on a web server.
Change midi.xsd to be:
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetnamespace="/my/midi/namespace">
And then change octaves.xsd to say:
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:midi="/my/midi/namespace">
<xs:import namespace="/my/midi/namespace" schemaLocation="midi.xsd"/>
...
<xs:element name="from" type="midi:note" />
Note the use of xs:import rather than <xs:include> The two are very different - you use import for bringing in other namespaces, and include for inline inclusion of other schema files into the current namespace.
Note also that /my/midi/namespace can be anything you want, it's an arbitrary identifier.
I'm pretty sure the problem is to do with the fact that midi.xsd is a local file
Nope, not relevant.

XML schema and problem when deriving from mixed type

I have following XML schema:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="content" type="contentType"/>
<xs:complexType name="contentType">
<xs:complexContent>
<xs:extension base="versionedElementType">
<xs:sequence>
<xs:element name="item" type="itemType" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="itemType" mixed="true">
<xs:complexContent>
<xs:extension base="itemTypeBase">
<xs:sequence>
<xs:element name="order" type="xs:unsignedInt"/>
<xs:element name="id" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- Simple type convert to complex type -->
<xs:complexType name="itemTypeBase" mixed="true">
<xs:simpleContent>
<xs:extension base="itemDescriptionType">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<!-- Simple type -string restriction -->
<xs:simpleType name="itemDescriptionType" >
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="64"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="versionedElementType">
<xs:attribute name="version" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
which I use to validate this XML instance (I want to mix the text in the 'item' element with sub-elements 'order' and 'id'):
<?xml version="1.0" encoding="UTF-8"?>
<content xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Content.xsd"
version ="1.0">
<item>Description here...
<order>2</order>
<id>2</id>
</item>
</content>
Whatever I did the validation still says taht there is an error:
The content type of a derived type and that of its base must both be mixed or both be element-only. Type 'itemType' is mixed, but its base type is not.
But I can see that both types - itemType and itemTypeBase are MIXED!!
Thanks a lot
STeN
First of all the error which I see if I open your schema in Visual Studio 2010 is:
The derived type and the based type
must have the same content type.
In you current schema the type itemTypeBase is defined with respect of the <xs:simpleContent> and derived type itemType with the respect of <xs:complexContent> which is not allowed. Either you allow no sub-elements and use <xs:simpleContent> or you do use child elements and use <xs:complexContent>.
I personally don't like and don't use mixed types. If I understand you correct you want to make some restrictions in the text from the content. You want to have the content length between 1 and 64 characters. But <order>2</order>, <id>2</id> and all whitespace, inclusive the new line characters, are also a part of the content. If you want that <item> has simple content, then you can not insert child elements inside.
So the pragmatical solution would be go away from the mixed model and use the XML document in the form
<?xml version="1.0" encoding="utf-8"?>
<content xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Content.xsd"
version ="1.0">
<item>
<description>Description here...</description>
<order>2</order>
<id>2</id>
</item>
</content>
where Content.xsd is
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="content" type="contentType"/>
<xs:complexType name="contentType">
<xs:sequence>
<xs:element name="item" type="itemType"
minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="version" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="itemType">
<xs:sequence>
<xs:element name="description" type="itemDescriptionType"/>
<xs:element name="order" type="xs:unsignedInt"/>
<xs:element name="id" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="itemDescriptionType" >
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="64"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
All will be very simple and clear.

Resources