如何从XSD创建XML [英] How to Create xml from xsd

查看:90
本文介绍了如何从XSD创建XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用xsd.exe创建了类文件,然后按照下面的链接中的说明创建了xml文件.

^ ]

它工作正常,但只需要一个xsd文件.其给定错误为同一表不能是两个嵌套关系中的子表",因为一个父元素的子元素具有相同的名称.
尝试说明以下情况

I have created class file using xsd.exe and then created xml file as given on the link below

Creating an XML file based on XSD[^]

Its working perfectly but for one xsd file. Its giving error as "The same table cannot be the child table in two nested relations " Its because child element of one parent element has same name.
Trying to illustrate the case below

<Parent>
  <Child1>
    <ChildDetails>
         <Name>
         <Age>
    </ChildDetails>
  </Child1>
   <Child2>
      <ChildDetails>
           <Name>
           <Age>
      </ChildDetails>
  </Child2>
</Parent>


它给出错误同一表"ChildDetails"不能是两个嵌套关系中的子表".
在网上检查后,我将必须按照以下链接所述手动重命名元素名称
http://social.msdn.microsoft.com/Forums/zh-CN/xmlandnetfx/线程/22f98352-83b9-4638-a306-34a36a11e4d6 [
一直试图在xsd.exe生成的Class文件中更改元素名称,但仍使用原始元素名称生成.

任何帮助将不胜感激.


It gives error "The same table "ChildDetails "cannot be the child table in two nested relations "
On checking on net understand I will have to rename the element name manually as mentioned on the following link
http://social.msdn.microsoft.com/Forums/en-US/xmlandnetfx/thread/22f98352-83b9-4638-a306-34a36a11e4d6[^]

"The DataSet class in .NET 2.0 (Visual Studio 2005) still has the limitation of not supporting different nested tables with the same name. Therefore you will have to introduce an XML transform to pre-process the XML (and schemas) before you load them up into the DataSet."

Have been trying to change the element name in the Class file generated by xsd.exe but its still generating with the original element name.

Any help would be highly appreciated.

推荐答案

根据您发布的内容,看来<Name><Age>没有关闭.这将导致嵌套块的出现,这可能是您的架构不允许的.

您需要添加结束标记(例如</Name>)或使用属性并使标签具有自闭合功能,例如<Name first="..." last="..." />
Based on what you posted, it appears that <Name> and <Age> are not closed. That would result in the appearance of nested blocks, which your schema presumably does not permit.

You need to add either a closing tag, such as </Name>, or use attributes and have the tags self-close, such as <Name first="..." last="..." />


这篇关于如何从XSD创建XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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