import not working for xsd - xsd

I am a bit new to XSD, I tried updating a XSD and it is giving me the below error
Code i have added:
<xs:element ref="cards:paymentrelationship" />
For this i have added below thing to the xml:schema
xml:cads="uri"
and below import statement
<xs:import namespace="cads" schemalocation="uri"/>
i am getting the below error
componenets from this namespace are not referencable from this xsd , appropriate import tag needs to be added

Here the cards text is a namespace-prefix that you are using in the xsd.
The namespace-prefix must be associated to an namespace-value (here "uri") not with xml: attribute but rather xmlns::
xmlns:cards="uri"
Then you need to use correctly you import statement: target an external xsd resource that is defining the elements belonging to namespace uri. Let's say you have another xsd called 'simpleTypes.xsd', this xsd is declaring targetnamespace='uri', it is the one you have to import in your current XSD:
<xs:import namespace="uri" schemalocation="./simpleTypes.xsd"/>
To start with XML namespaces, I would advice starting with w3schools rather than looking at the W3C specifications.
Have a look at:
http://www.w3schools.com/xml/xml_namespaces.asp
http://www.w3schools.com/xml/schema_schema.asp

Related

Inherit XSD namespace prefix

I have a lot XSD which access each other.
Since I'm changing to JAXB I'm currently looking for a straightforward way to add namespaces to the xsds according to their folder structure.
My main issue at the moment is to add the namespace to the XSD itself, to the import in the accessing file and also to the prefix definition in the accessing file.
Here a small example (not quite real live)
User.xsd - targetNamespace="common.user"
Message.xsd - targetNamespace="common.message"
Email.xsd - targetNamespace="email" xmlns:user="common.user" xmlns:message="common.message"
import namespace="common.user" schemaLocation="./common/user.xsd"
import namespace="common.message" schemaLocation="./common/message.xsd"
When I now have a new Message.xsd schema I have to duplicate 90% of my xsd header.
I was creating a Namespace.xsd xmlns:user="common.user" xmlns:message="common.message" which is then included by Email.xsd. But accessing e.g. user:name did not work.
Is there a way to save the namespace-prefix definition in a central XSD-file so I do not have to define them in every single xsd?
Also, is there a way to not need to set the namespace in the import when it is already defines in the imported xsd as targetNamespace?
I think (not 100% sure though) that including into the schema A a schema B which imports another schema C will give you access to C in A.
However you will still need to declare the namespace prefix (like xmlns:user="common.user").
ps. Just a warning - never ever do chameleon schemas. It does not seem that you plan to, but i still wanted to warn.

basic XSD importing and xsd.exe?

I have a main xsd built against another one containing shared types (they are in the same directory).
That's the header of the main one :
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="XMLSchema_Module.xsd"
xmlns:cs="XML_Common"
targetNamespace="XMLSchema_Module.xsd"
elementFormDefault="qualified">
<xsd:import schemaLocation="XML_Common.xsd" namespace="XML_Common"/>
That's the header of the shared types one :
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="XML_Common"
elementFormDefault="qualified">
That's the shared type enumeration I want to use in an attribute of the main schema :
<xsd:simpleType name="TypesType">
<xsd:restriction base ="xsd:token">
<xsd:enumeration value="int"/>
And here is the reference in the main one :
<xsd:attribute name="Type" type="cs:TypesType"/>
I am using xsd.exe to generate the serialization classes (integrated in the build process as a pre-build event). These xsd were built using VisualStudio.
<Exec Command=""C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\xsd.exe" XSchemas\XMLSchema_Module.xsd /c /o:SerializationClasses /n:ScenarioManager" />
I am translating the actual message I obtain :
The type XML_Common:TypesType is not declared or is not a simple type.
It seems to be an import problem but I do not know how to solve it.
My bad, it seems that xsd.exe does not resolve schema imports.
From this article :
Now that the type has been defined in another file, the xsd.exe will
generate this error if you attempt to create the create the Request
XML: C:\Solution\Project>xsd.exe Request.xsd /c Schema validation
warning: Type 'http://www.Example.com/Types:Meeting' is not declared.
Warning: Schema could not be validated. Class generation may fail or
may produce incorrect results. Error: Error generating classes for
schema 'C:\Solution\Projects\Request'.
The datatype 'http://www.Example.com/Types:Meeting' is missing. If you would like more help, please type "xsd /?". This is due to the
fact that the xsd.exe does not use the schemaLocation hint to find the
imported schema. You’ve got to include it as a parameter. in your
xsd.exe call: C:\Solution\Project>xsd.exe Types.xsd Request.xsd /c
It should be emphasized that despite the pessimistic opening of LB40's answer, its last sentence yields the solution: in your xsd.exe call you have to include the referenced xsd as a parameter before the referencing xsd:
C:\Solution\Project>xsd.exe Types.xsd Request.xsd /c
This will generate a single cs source file containing the classes for both the schemas.

xjc generated code references OverrideAnnotationOf annotation from sun internal package

I'm trying to generate Java classes from a set of XML schemas. The following binding file is used to handle mixed content in the schemas:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1"
xmlns:xjc= "http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc">
<jaxb:globalBindings generateMixedExtensions="true"/>
</jaxb:bindings>
The code generation works fine but one of the generated classes has an #OverrideAnnotationOf from the com.sun.xml.internal.bind.annotation package. This package is included in rt.jar but the regular java compiler can't find it (and probably shouldn't find it because it is sun internal).
Is there a way to deal with the mixed content and not have the OverrideAnnotationOf from a sun internal package in my generated code?
In Java 6 and up, oracle moved the JAXB implementation embedded within the JRE to a different package to prevent potential collisions with the external JAXB reference implementation.
So the class OverrideAnnotationOf got moved from package com.sun.xml.bind.annotation to package com.sun.xml.internal.bind.annotation.
The embedded xjc, however, still generates java files that are annotated with com.sun.xml.bind.annotation.OverrideAnnotationOf(!)
Therefore, the JAXB implementation shipped with Java 7 will not understand its own output generated with generateMixedExtensions="true". Even if you use the -XDignore.symbol.file option.

How to correctly use GenerateDS for DDEX XML binding

I am interested in Python XML binding for reading input files conforming to this schema:
http://ddex.net/xml/ern/341/release-notification.xsd
This XSD depends on a number of other ones though, most importantly:
http://ddex.net/xml/20120404/ddexC.xsd and
http://ddex.net/xml/20120404/ddex.xsd
My first attempt is by using generateDS. I am able to successfully generate binding for release-notification.xsd if I use --no-process-includes with:
./generateDS.py --no-process-includes -o release-notification.py release-notification.xsd
However, this leaves me with a Python object that is mostly useless since most of the ComplexTypes are defined in ddexC.xsd.
If I try it without --no-process-includes, I get:
RuntimeError: Extension/restriction recursion detected.
Suggest you check definitions of types ArtistRole and ArtistRole.
The definition referred to is this one:
<xs:element name="ArtistRole" maxOccurs="unbounded" type="ddexC:ArtistRole">
....
<xs:complexType name="ArtistRole">
<xs:simpleContent>
<xs:extension base="ddex:ArtistRole">
....
So it seems like the ddex and ddexC namespaces get mixed up somehow and a circular reference is created.
Any advice here?
You may want to check out https://github.com/ddexnet which has a ddex lint script which you can use to generate full python objects which are validated against the full ERN schema located at http://ddex.net/xml/2010/ern-main/32.
(The linter makes use of the ddexC namespace under the hood too).
I have created an object model for New Release message as part of a DDEXUI I am working on which may help you, The ddex module should give you something you can use. I plan to strip it in to a separate module at some point. For an example of how to use it, see the test directory.

JAXB : use local schemaLocation to generate Java classes

I am trying to generate Java classes from a XSD schema using the xjc command that comes with JAXB.
My schema looks like:
<xs:schema xmlns="..."
xmlns:ext="http://schemas.myco.com/ext" ... >
<xs:import namespace="http://schemas.myco.com/ext"
schemaLocation="http://myco.com/schemas/ext.xsd"/>
...
The problem is that the schemaLocation URI does not exist and I can not modify the XSD file. That is why the generation process fails with errors such as "src-resolve: Cannot resolve the name 'ext:Resource_Type' to a(n) 'type definition' component".
Is there any way to force JAXB to use a local copy of ext.xsd file during the process without modifying the original XSD file ?
Two possible solutions:
JAXB Episode File:
http://weblogs.java.net/blog/2006/09/05/separate-compilation-jaxb-ri-21
or
XML Catalogs (search Google)

Resources