Questions about object classes generated by XSD

Source: Internet
Author: User
Tags class generator

1. There may be mutual nesting in the XSD file, which means the XSD is powerless.

Http://geekswithblogs.net/mnf/archive/2008/07/22/generate-c-class-from-xsd-file.aspx

| Home | "Login Failed for user" may mean "database name is invalid">

Generate C # class from XSD file.

I have an existing C # file, generated a long time ago from XSD definition.

The XSD files were changed, and proxy class shoshould be regenerated.

I 've tried to use XML schema definition tool (xsd.exe) to generate C # class, but it returned the error: "The datatype is missing ".
I 've actually have two XSD files-Outer and imported

Thanks to the post: xsd.exe is kicking my butt, man... Redux, it pointed meSpecify all necessary filesOn the CommandLine.

Note that name of generated file is combined from the files listed

I 've created the batch file to be able to rerun it

Callxsd. bat

@ Call "C: \ Program Files \ Microsoft Visual Studio 8 \ Vc \ vcvarsall. Bat" x86

Xsd.exe outer. XSD imported. XSD/classes/L: CS/n:MyNamespace

Rem rename outer_imported.cs as outer. CS

Pause

By some reason the generated file created in some non-default encoding, which inserts 3 Characters

Timeout» timeout in the beginning. It is a minor annoyance, but when I delete them, vs shows me a warning, that wrong encoding cocould prevent keeping history.

The next issue was that the new XSD (. NET Framework 2.0 and 3.5) generates C # classes differently with what 1.0/1.1 xsd.exe did.

In a few places 1.1 version generated custom collection of objects, but new XSD. EXE generates array of objects, so I have to change the callto generated classes.
Another problem with XSD generated classes is that it disables step into Debugging even on methods that you extended in partial classes by specifyingDebuggerstepthroughattributeFor classes. workarounds are described inxsd.exe and debuggerstepthrough post. Issue reported to MS feedback.

I shocould try an XSD to. NET language code class generator that adds real punch to Microsoft's XSD tool.
Or Sample Code Generator 1.4.2.1

Another issue was that authors of XSD file added XSD: Choice elements and it creates extraItemschicetypeArray and enum. I described how I addressed it inmy post xmlchoicecollection class to access XSD generated properties for choice XML elements

That's pity, that minor changes in XSD file causes different class properties to be generated and essential code changes to access the new properties.

Http://www.hanselman.com/blog/XSDexeIsKickingMyButtManredux.aspx

Decomposing XSD and WSDL into abstract definitions of types and messages is a good thing, but it appears that Microsoft's tools don't adequately support embracing this approach? Or, I'm completelySans clue. For example, xsd.exe doesn't seem to be able to communicate with xs: Import elements when Generating Wrapper Classes. wsdl.exe has the same problem.

Anyone have any thoughts on this? I 'd like not to wait until Whidbey to be able to describe my messages and contracts and generate a schtickel of code.Updated with Note: rant retracted... for now! See below

Here's a very trivial example straight from dare's great msdn article.

Import. XSD:

Http://www.w3.org/2001/XMLSchema
Targetnamespace = "http://www.import.org" elementformdefault = "qualified">






The outer XSD:


Http://www.w3.org/2001/XMLSchema"
Targetnamespace = "http://www.example.org"
Xmlns: TNS = "http://www.example.org"
Xmlns: IMP = "http://www.import.org">
Http://www.import.org "schemalocation =" file: // C:/import. XSD "/>

This schema appears to be valid-in fact, the. NET Framework agrees. But when you try and run the outer schema through xsd.exe, you get the following error:

C: \> XSD/C root. XSD
Microsoft (r) XML schemas/datatypes support Utility
[Microsoft (R). Net Framework, version 1.1.4322.573]
Copyright (c) Microsoft Corporation 1998-2002. All rights reserved.
Schema Validation warning: Type 'HTTP: // www.import.org: roottype' is not declared. An error occurred at file: // C:/root. XSD, (10, 3 ).

Warning: schema cocould not be validated. Class generation may fail or may produce incorrect results.

Error: Error generating classes for schema 'root '.
-The datatype 'HTTP: // www.import.org: roottype' is missing.

Update:Tomas was kind enough to point out not only that I had originally postedSame schema twice, DOH! But also, more importantly, that XSD. EXE doesn't resolve schemalocation on imports or includes, presuambly because the W3C schema spec describes the schemalocation attribute asHint,Not a true location.

I'm back in business as I ran XSD. EXE again with all necessary Files specified on the CommandLine, in order to give XSD. EXE a choice of Namespaces-as opposed to hoping it wowould somehow glean my intent!

I'm too used to using xmlspy, XSLT and other tools for generating CS code. Good stuff, thanks Tomas! Not only was I without a clue, I was alsoSin una Pista,Sans indice- Ich war ohne einen anhaltspunkt. That'll teach me not to post a rant in haste!

Http://msdn.microsoft.com/en-us/library/ms950721

Q: Why doesn't xsd.exe support the schemalocation attribute on imports and between Des?

A:The W3C XML schema recommendation describes this attribute as a hint, which can be ignored by processors that can use alternate means to locate schemas. xsd.exe only uses Schemas that are specified through the command line to convert schema. XSD, which imports schema B. XSD.

 
Xsd.exe/c a. xsd B. XSD

Also, the wsdl.exe application, considered a sister application to xsd.exe, can be downloaded from the Web. If you do this and use the wsdl.exe, you wowould follow schemalocation hints in imports and DES.

Google obtains the xsd2code tool below the shrimp. The installation is complete, but this plug-in does not appear in vs. I don't know what to ask, but it hasn't been solved yet.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.