XSD.EXE and included schemas?
Here’s a basic question that I can’t seem to figure out: I need to import a schema (specifically OFX schema) into .NET and I’m trying to do this with XSD. The schema files are broken up into linked schema files (ie. other schemas are included into the ‘main’ schema file). The schemas work fine when I load them up the into Visual Studio for display. The designer properly shows the schema and all of the related included types.
However when I run XSD.EXE against the schema it complains that all the imported schema types are missing and ultimately fails to generate the class(es) for the schema.
Looking at XSD.EXE I don’t see anyway to specify the whole lot of files to import and apparently XSD.EXE doesn’t look at the includes which look something like this:
<xsd:schema targetNamespace="http://ofx.net/types/2003/04" xmlns:ofx="http://ofx.net/types/2003/04" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="OFX_Banking_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_BillPay_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_BillerDelivery_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_BillerDirectory_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_CreditCard_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_Email_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_Image_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_InterTransfer_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_Investment_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_Loan_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_Profile_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_SecuritiesList_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_Signon_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_Signup_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_Tax1098_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_Tax1099_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_TaxW2_Message_Wrappers.xsd"/>
<xsd:include schemaLocation="OFX_WireTransfer_Message_Wrappers.xsd"/>
<xsd:complexType name="OFXRequestType">
Anybody have any idea how I can do this?
Also I seem to remember that there’s some way to do the type generation from within Visual Studio without explicitly running XSD. It sure would be nice that once the schema is loaded in VS, to right click generate classes/dataset right out of the designer…
The Voices of Reason
# re: XSD.EXE and included schemas?
Main Protocol xsd:
<xsd:schema targetNamespace="http://ofx.net/types/2003/04" xmlns:ofx="http://ofx.net/types/2003/04" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Investment Messages xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ofx="http://ofx.net/types/2003/04" targetNamespace="http://ofx.net/types/2003/04" elementFormDefault="unqualified">
I thought maybe that XSD is not findng the other files, but looking at FileMon - it's definitely opening the other schema files. So it appears it's not happy consolidating what it finds in the includes.
The OFX files have a special dotnet version for the main xsd file but from what I can glean from it the only thing that does if fix up the array/collection implementation so that .NET can properly create those types which should not be an issue for the child objects. Also doesn't work with the other non dotnet specific schemas.
In case anybody's looked at this the files come from the ofx main site here:
http://www.ofx.net/ofx/de_spec.asp
# re: XSD.EXE and included schemas?
Pull up the File Properties on the XSD file in visual studio. Set the "Custom Tool" property to MSDataSetGenerator. Right click the file and choose "Run Custom Tool"
# re: XSD.EXE and included schemas?
Something like this: xsd.exe mainschema.xsd linkedschema1.xsd linkedschema2.xsd .....
Hope that helps.
# re: XSD.EXE and included schemas?
# re: XSD.EXE and included schemas?
Tested: xsd.exe OFX3_Protocol_dotNET.xsd /c
and I got a .cs file out without any problems... Am I testing with the wrong xsd?
# re: XSD.EXE and included schemas?
Have you tried XSDObjectGen? It provides a 2005 command line executable. A couple snippets from the doc:
Support for the most popular XML schema constructs: Supports (inheritance, groups, abstract types, elements, attributes, complexType, simpleType, enumeration, any, anyType). Limited support for “interesting” schema constructs (choice, substitution groups , complex type restriction, complex type extension using regular expressions). No support for “questionable” schema constructs (union, redefine).
Multipart schema support: Some schemas reference other schemas via include constructs. The generator provides full support for schemas that span multiple files using the XML Schema include statement. Some schemas are defined by incorporating types defined in other schemas and importing them. The sample code generator reads these multi-namespace schemas and optionally generates a file per XML namespace encountered. No support is provided for a file per include, since these all create a single namespace.
# re: XSD.EXE and included schemas?
As it turns out though the _dotnet file doesn't work as it actually is a different schema that's not compatible with the stuff I need to parse against. The version 2.0.1 schema and the _classic schemas have the right data.
I managed to get some test data set up and it appears it's parsing from deserialization, but I end up with null data beyond the top level element...
I think it might just be easier to parse the document with the DOM rather than trying fit the damn class mapping to it... <s>
# re: XSD.EXE and included schemas?
XSD.EXE is limited, that's why I use CodeXS(Open Source). It suports multi included schema's and creates an output file per schema. It's using a plugin architecture so you can modify the output with your own codemodifiers.
Check out the url below for a full feature list and to download CodeXS
# re: XSD.EXE and included schemas?
# re: XSD.EXE and included schemas?
Curtis
# re: XSD.EXE and included schemas?
Did you get a good solution with the xsd.exe's limitation on schemalocation? I tried all the suggested approaches for a schema import a ton of other schemas -- a standalone schema in STAR5.0.4, and none of them worked for me.
Did you use DOM to parse it, or using other tools?
Thanks much,
Junlia
# re: XSD.EXE and included schemas?
Following is the command that I used
"c:\program files\microsoft visual studio 8\sdk\v2.0\bin\xsd.exe" /c /l:c# /n:<YorNamespace> EntityA.xsd Imported_01.xsd
Where Imported_01.xsd is referenced in the xsd file like below
<xs:import namespace = "http://../Imported_01/" schemaLocation = "http://../Imported_01.xsd"/>
I also tried the following but that did not work
"c:\program files\microsoft visual studio 8\sdk\v2.0\bin\xsd.exe" /c /l:c# /n:<YorNamespace> EntityA.xsd http://../Imported_01.xsd
# re: XSD.EXE and included schemas?
# re: XSD.EXE and included schemas?
You can download it here (http://www.microsoft.com/downloads/details.aspx?familyid=89e6b1e5-f66c-4a4d-933b-46222bb01eb0&displaylang=en)
[]'s
Cleydson
http://weblogs.pontonetpt.com/cleydson
# re: XSD.EXE and included schemas?
AFAIK, XSDObjectGen.exe is deprecated and MS is now pushing XSD.exe more. I don't have any hard evidence other than what I have heard thru some of my MS friends.
# re: XSD.EXE and included schemas?
Maybe you can find it on the net. I would distribute it but I am unable to locate the readme for it and the license agreement to see if I can legally do so.
Hope this helps ya.
Ken
# re: XSD.EXE and included schemas?
xsd.exe sub1.xsd sub2.xsd sub3.xsd main.xsd...
# re: XSD.EXE and included schemas?
Can you explain in detail what is it that you did to generate the classes? I'm actually trying to use XSD.EXE to create classes for B2MML schemas. The guy in WBF who is in charge of these schemas named you and this post as the solution, but I can't seem to understand what is it that you did...
# re: XSD.EXE and included schemas?
In order for xsd.exe to work i had to copy the four files into c:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin and then run XSD.exe.
# re: XSD.EXE and included schemas?
# re: XSD.EXE and included schemas?
http://hosca.com/blog/post/2008/12/26/Generating-C-classes-from-FpML-Schema.aspx
# re: XSD.EXE and included schemas?
I've been able to generate the .cs file by just giving the complete address of the dependencies, like this:
schemaLocation="file:///c:/newDS_app2.xsd"
and running XSD.exe WITHOUT the dependencies!
xsd /d /l:cs c:\newDS.xsd
The class got created, but still can't make it compatible with the IDE designer!
# re: XSD.EXE and included schemas?
c:\program files\microsoft sdks\windowsv\7.0a\bin> xsd.exe "c:\schemas\include1.xsd" "c:\schemas\include2.xsd" "c:\schemas\include3.xsd"
"c:\schemas\primary.xsd" /c /l:vb
# re: XSD.EXE and included schemas?
Am not sure what is the solution in .net. And i need to use the extended xsd to generate a class.
Thanks
Sumana
# re: XSD.EXE and included schemas?
# re: XSD.EXE and included schemas?
Well, in 2019, xsd.exe still can't read import element... Microsoft
# re: XSD.EXE and included schemas?
@ThePukeOne - Translation: It'll never happen 😃
# re: XSD.EXE and included schemas?
If you have a lot of xsd, you should use a configuration file. For example GenerateClassFromXSD.xml :
<xsd xmlns='http://microsoft.com/dotnet/tools/xsd/'>
<generateClasses language='CS' namespace='Namespace.subnamespace'>
<schema>A2.xsd</schema>
<schema>A21.xsd</schema>
<schema>.\A22.xsd</schema>
</generateClasses>
</xsd>
It is very important to have the ".\" in last xsd declaration (otherwise, you will have a too big filename > 260 car.)
xsd /p:GenerateClassFromXSD.xml
See the final tips here : https://stackoverflow.com/questions/3859319/tool-that-can-combine-many-xsd-files-into-one/7000894
# re: XSD.EXE and included schemas?