以编程方式(C#)创建xml模式 [英] Programmatically (c#) create xml schema

查看:109
本文介绍了以编程方式(C#)创建xml模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下xml模式,

Suppose, I have the following xml schema,

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Tab1">
<xs:complextype>
<xs:sequence>
<xs:element minoccurs="0" maxoccurs="10" name="Test1" type="xs:string" />
<xs:element minoccurs="0" maxoccurs="10" name="Test2" type="xs:string" />
<xs:element minoccurs="0" maxoccurs="10" name="Test3" type="xs:int" />
</xs:sequence>
</xs:complextype>
</xs:element>
</xs:schema>



然后,我必须在每个元素中添加一些其他值
(例如:state ="kerala" url ="mylinkurl")

因此,最终的xml模式输出将如下所示:
(请参阅元素标签)



then, I have to add some additional values with each element
(Eg: state="kerala" url="mylinkurl")

So the final xml schema output will be as follows:
(see the element tags)

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Tab1">
<xs:complextype>
<xs:sequence>
<xs:element minoccurs="0" maxoccurs="10" name="Test1" type="xs:string" state="kerala" url="mylinkurl" />
<xs:element minoccurs="0" maxoccurs="10" name="Test2" type="xs:string" state="tamilnadu" url="mylinkurl" />
<xs:element minoccurs="0" maxoccurs="10" name="Test3" type="xs:int" />
</xs:sequence>
</xs:complextype>
</xs:element>
</xs:schema>



如何添加这些名称&以编程方式(使用C#)实现价值?请提供示例代码.



How can add these name & value programmatically (using c#)? Please provide a sample code.

推荐答案

看看
Take a look at the XElement[^] class.

With it you can add new XElements and XAttributes along with their values to an existing XElement.


这篇关于以编程方式(C#)创建xml模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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