XSD.exe处理生成类中的混合内容类型? [英] XSD.exe handling of mixed content types in generate classes?

查看:67
本文介绍了XSD.exe处理生成类中的混合内容类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从包含某些内容的XSD生成类定义

如:


< xs:complexType name =" foo" ; mixed =" true">

< xs:choice minOccurs =" 0" maxOccurs =" unbounded">

< xs:element name =" bar" type =" something" />

...

< xs:element name =" baz" type =" somethingelse" />

< / xs:choice>

< / xs:complexType>


XSD.exe生成的C#代码创建了一个具有

对象数组的类,以允许任意数量的元素(反映

maxOccurs =" unbounded" ;),但似乎不允许在bar和/或baz元素之间发生可能的文本块

。当我实际将

反序列化为包含此类文本的XML生成的类结构时,我没有得到

错误或投诉,但生成的对象具有长度为1的数组
只包含bar / baz元素,没有反映XML文件中的文本




基于谷歌搜索我发现一篇文章暗示XSD.exe并不是很好地处理混合内容,但是这个例子比选择合成器使用了序列而不是
。从我的经验来看,在

" choice"的情况下它完全没有处理它!


无论如何,我所有这些都是基于旧的。 .Net的版本,我想知道是否

VS 2003版本的XSD.exe在混合内容架构方面做得更好。

另外,我是否有可能处理这些通过提供一些

自定义序列化/反序列化代码的各种情况?


提前致谢,

Bill

解决方案

Hello Bill,


什么是text chunks酒吧和/或巴兹之间发生的?你能给我一个样品吗?谢谢。

Luke


" Microsoft安全声明:您是否安装了补丁?
Microsoft安全公告MS03-026? ?如果不是,Microsoft强烈建议您使用以下链接查看有关Microsoft的信息

安全公告MS03-026
http://www.microsoft.com/security/se...s/ms03-026.asp 和/或

访问Windows Update,访问 http:// windowsupdate.microsoft.com 安装

补丁。从Windows Update站点运行SCAN程序将有助于确保您掌握所有安全补丁,而不仅仅是MS03-026。


[我在几个小时前发布了这个回复,但因为它似乎没有

使它可能重复它...]

>
只是文本,正如您在混合=真中所期望的那样内容模型。想想你用来模拟带有嵌入式< p>的XHTML文本的XSD的
元素等


Bill

" MSFT" <卢****** @ online.microsoft.com>在消息中写道

news:7l ************** @ cpmsftngxa06.phx.gbl ...

Hello Bill,

什么是文本块酒吧和/或巴兹之间发生的?你能给我一个样品吗?谢谢。

Luke

Microsoft安全公告:您是否安装了Microsoft安全公告MS03-026的补丁?如果不是,Microsoft强烈建议您查看以下关于Microsoft的信息安全公告MS03-026
http://www.microsoft.com/security/se...s/ms03-026.asp 和/或
http://windowsupdate.microsoft.com 上访问Windows Update以安装
补丁。从Windows Update站点运行SCAN程序将有助于确保您掌握所有安全补丁,而不仅仅是MS03-026。



< blockquote>我认为问题应该与text

chunk的命名空间有关。如果没有已知的命名空间,xsd.exe将生成错误。我相信以下代码应该有效:


< xs:element name =" bar" type =" xs:int" />

< xs:element name =" bat" type =" xs:int" />

< xs:element name =" baz" type =" xs:int" />


Luke


(此帖子按原样提供,不作任何保证,并且不授予

权利。)


I''m trying to generate class definitions from an XSD that contains something
like:

<xs:complexType name="foo" mixed="true">
<xs:choice minOccurs = "0" maxOccurs="unbounded">
<xs:element name = "bar" type = "something"/>
...
<xs:element name = "baz" type = "somethingelse"/>
</xs:choice>
</xs:complexType>

The C# code generated by XSD.exe creates a class that has an array of
objects to allow for an arbitrary number of elements (reflecting the
maxOccurs="unbounded"), but doesn''t appear to allow for possible text chunks
occurring between the bar and/or baz elements. When I actually deserialize
into the generated class structure from an XML containing such text I get no
errors or complaints, but the resulting objects have arrays of length 1
containing just the bar/baz element and nothing reflecting the text that is
in the XML file.

Based on a google search I found an article that implies XSD.exe doesn''t
really handle mixed content well, but the example used a sequence rather
than a choice compositor. It appears from my experience that, in the case of
"choice" it doesn''t handle it at all!

Anyway, I''m basing all this on the "old" version of .Net and am wondering if
the VS 2003 version of XSD.exe does any better with mixed content schema.
Also, is it possible for me to handle these sorts of cases by providing some
custom serialize/deserialize code?

Thanks in advance,
Bill

解决方案

Hello Bill,

What is the "text chunks" occurring between the bar and/or baz? Can you
give me a sample? Thanks.
Luke

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/se...s/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026."


[I posted this reply some hours ago, but since it dosen''t appear to have
made it am possibly duplicating it...]

Just text, as you would expect in a mixed = "true" content model. Think of
the XSD you''d use to model XHTML text with embedded <p> elements, etc.

Bill
"MSFT" <lu******@online.microsoft.com> wrote in message
news:7l**************@cpmsftngxa06.phx.gbl...

Hello Bill,

What is the "text chunks" occurring between the bar and/or baz? Can you
give me a sample? Thanks.
Luke

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/se...s/ms03-026.asp and/or to visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026."



I think the problem should be related to the namespace for the "text
chunks". Without a known namespace, xsd.exe will generate an error. I
believe following code should work:

<xs:element name = "bar" type = "xs:int"/>
<xs:element name = "bat" type = "xs:int"/>
<xs:element name = "baz" type = "xs:int"/>

Luke

(This posting is provided "AS IS", with no warranties, and confers no
rights.)


这篇关于XSD.exe处理生成类中的混合内容类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆