xsd.exe_XSD.exe踢了我的屁股,伙计... redux

xsd.exe

xsd.exe

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 completely sans clue.  For example, XSD.exe doesn’t seem to be able to cope with xs:import elements when generating wrapper classes.  WSDL.exe has the same problem. 

将XSD和WSDL分解为类型和消息的抽象定义是一件好事,但是看来Microsoft的工具不能充分支持采用这种方法吗? 或者,我完全没有线索 例如,在生成包装器类时,XSD.exe似乎无法应付xs:import元素。 WSDL.exe具有相同的问题。

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 ;)

有人对此有任何想法吗? 我不想等到Whidbey能够描述我的消息和合同并生成代码之后。 更新为“注意:Rant已撤回...暂时! 见下文 ;)

Here’s a very trivial example straight from Dare's great MSDN Article.

这是一个非常简单的例子,直接来自Dare的出色MSDN文章

Import.xsd:<?xml version="1.0" encoding="utf-8" ?><xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema 
targetNamespace="http://www.import.org" 
elementFormDefault="qualified">       <xs:complexType name="rootType" >              <xs:sequence>                  <xs:element name="child1" type="xs:string" maxOccurs="2" />                  <xs:element name="child2" type="xs:string"/>            </xs:sequence>      </xs:complexType></xs:schema>

Import.xsd: <?xml version =“ 1.0” encoding =“ utf-8”吗?> <xs:schema xmlns:xs = http://www.w3.org/2001/XMLSchema targetNamespace =“ http://www.import.org” elementFormDefault =“ qualified”> <xs:complexType name =“ rootType”> <xs:sequence> <xs:element name =“ child1” type =“ xs:string” maxOccurs =“ 2” /> <xs:element name =“ child2” type =“ xs:string” /> </ xs:sequence> </ xs:complexType> </ xs:schema>

The Outer xsd:

外层xsd:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema
 targetNamespace="http://www.example.org
 xmlns:tns="http://www.example.org"
 xmlns:imp="http://www.import.org">
<xs:import namespace="http://www.import.org" schemaLocation="file:///c:/import.xsd"/>
 <xs:element name="root" type="imp:rootType" />
</xs:schema>

<?xml版本=“ 1.0”编码=“ UTF-8”吗?> <xs:schema xmlns:xs =“ http://www.w3.org/2001/XMLSchema targetNamespace =“ http://www.example.org xmlns:tns =“ http://www.example.org xmlns:imp =“ http://www.import.org ”> <xs:import namespace =“ http://www.import.org ” schemaLocation =“ file:/// c:/import.xsd” / > <xs:element name =“ root” type =“ imp:rootType” /> </ xs:schema>

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:

此架构似乎有效? 实际上,.NET框架对此表示同意。 但是,当您尝试通过xsd.exe运行外部架构时,会出现以下错误:

C:\>xsd /c root.xsdMicrosoft (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).

C:\> xsd / c root.xsd Microsoft(R)Xml架构/数据类型支持实用程序[Microsoft(R).NET Framework版本1.1.4322.573] 版权所有(C)Microsoft Corporation 1998-2002。 版权所有。 模式验证警告:未声明类型'http://www.import.org:rootType' 在file:/// C:/root.xsd(10,3)处发生错误。

Warning: Schema could 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.

错误:为架构“根”生成类时出错。 -数据类型“ http://www.import.org:rootType”丢失。

Update: Tomas was kind enough to point out not only that I had originally posted the same 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 as a hint, not a true location.

更新: Tomas很友好地指出,不仅我最初发布了相同的TWICE模式,哦! 而且,更重要的是, XSD.EXE不会解析导入或包含的schemaLocation ,这是因为W3C Schema规范将schemaLocation属性描述为提示而不是真实位置。

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 would somehow glean my intent!

当我再次运行XSD.EXE并在命令行上指定了所有必需的文件时,我又回到了企业,以便为XSD.EXE提供名称空间的选择-而不是希望它能以某种方式收集我的意图!

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 also sin una pistasans indice - Ich war ohne einen Anhaltspunkt.  That'll teach me not to post a rant in haste! 

我也习惯于使用XMLSpy,XSLT和其他工具来生成CS代码。 好东西,谢谢托马斯! 不仅是我没有线索,我也犯罪UNA PISTA,SANS指数之- ICH战争指数ohne einen Anhaltspunkt。 那会教我不要仓促行事!

翻译自: https://www.hanselman.com/blog/xsdexe-is-kicking-my-butt-manredux

xsd.exe

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值