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.
Related
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
I am trying to compile my iOS application using MonoTouch in Link SDK only mode. It compiles completely fine if I turn off linking entirely but it also produces a colossal binary which is not suitable for release mode.
Unfortunately, one of the libraries that I need somehow invokes Expression.Visit and I can't figure out how to instruct the linker to not strip it out. This results in this compilation error:
Error MT2002: Failed to resolve "System.Linq.Expressions.Expression System.Linq.Expressions.ExpressionVisitor::Visit(System.Linq.Expressions.Expression)" reference from "System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" (MT2002) (MyApp)
As per the documentation on custom linking, I have set up a linker file to try to stop this happening:
<?xml version="1.0" encoding="UTF-8" ?>
<linker>
<assembly fullname="System.Core">
<type fullname="System.Linq.Expressions.ExpressionVisitor">
<method signature="System.Linq.Expressions.Expression Visit(System.Linq.Expressions.Expression)" />
</type>
</assembly>
</linker>
Unfortunately, that doesn't have any effect - the error just happens as before.
The documentation mentions a preserve="fields" parameter I can supply to <type>, so I tried that:
<?xml version="1.0" encoding="UTF-8" ?>
<linker>
<assembly fullname="System.Core">
<type fullname="System.Linq.Expressions.ExpressionVisitor" preserve="methods" />
</assembly>
</linker>
That didn't work either.
I then introduced an XML syntax error into the file and the build failed saying it couldn't parse the linker file so I at least know that the file is being read.
But then I tried introducing errors into the assembly name:
<?xml version="1.0" encoding="UTF-8" ?>
<linker>
<assembly fullname="NonexistentAssembly">
</assembly>
</linker>
That caused an error, complaining that the assembly couldn't be resolved.
I then tried to mangle the type name:
<?xml version="1.0" encoding="UTF-8" ?>
<linker>
<assembly fullname="System.Core">
<type fullname="NonExistentType" preserve="methods" />
</assembly>
</linker>
Now, that just started showing the same "unable to resolve expressionvisitor::visit" error I was seeing before. It seems that type names are not checked.
Also, neither are signature names as this also presented the same compilation error.
<?xml version="1.0" encoding="UTF-8" ?>
<linker>
<assembly fullname="System.Core">
<type fullname="System.Linq.Expressions.ExpressionVisitor">
<method signature="jg98j23890rj2390erk90fk3ew!]['##'#'[" />
</type>
</assembly>
</linker>
So it seems that so long as you specify the assembly name and have a valid XML structure, the linker file does not cause any exceptions to be thrown. The documentation for the linker file though is not especially verbose for such a complex topic and includes numerous syntax errors, i.e.:
<type fullname="Foo" preserve="fields" />
<method name=".ctor" />
</type>
Also, it doesn't give a technical description of the linker file format so it's entirely possible that my definition is totally wrong.
I have also tried just skipping the linking of System.Core entirely with --linkskip=System.Core but this has no effect. I have tried this flag both with and without --xml.
In the MvvmCross project, I tried specifying a new class to call the Visit method in the same style as the LinkerPleaseInclude.cs file that gets added to every iOS project by the MvvmCross NuGet package:
[Preserve]
public class PleaseIncludeVisitor : ExpressionVisitor
{
public PleaseIncludeVisitor()
{
this.Visit(null);
}
}
Unfortunately, this also had no effect.
I am currently using Mono 3.2.6 ((no/9b58377) and Xamarin.iOS v7.0.7.2.
The main issue is that it is not possible to do code generation at runtime on iOS.
That means that a large part of System.Linq.Expressions would, normally, be impossible to provide under normal circumstances (just like System.Refection.Emit can't be provided).
To workaround this Xamarin.iOS has been providing an alternative implementation (that can interpret the most common expressions).
However the current code is not 100% API compatible with the .NET framework (that's fixed but not yet released). E.g.
System.Linq.Expressions.Expression System.Linq.Expressions.ExpressionVisitor::Visit(System.Linq.Expressions.Expression)
The above returns void in the current Xamarin.iOS (7.0.x) releases. That why the linker complains (it's not a bug) as it cannot find this member reference (and if it can't find it it cannot recreate the smaller, linked, assemblies). It is not possible to preserve a member that does not exist (which is why your attempts to use XML files or attributes won't help).
The current workaround is to identify which of your assemblies is using this API and rebuild it (from source) to use the existing System.Core.dll that is shipped with Xamarin.iOS.
Notes
I can't figure out how to instruct the linker to not strip it out.
The linker does not try to strip it out it tries to keep it in (i.e. it must load the reference to be able to save it back). However it cannot find that member in System.Core.dll making it impossible to provide a valid linked version of the assemblies.
<method signature="System.Linq.Expressions.Expression Visit(System.Linq.Expressions.Expression)" />
That's asking to preserve something that does not exist. It will be ignored, i.e. when the void-returning version is found it will not match the XML description.
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.
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.
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)