C#生成XSD规范,利用XmlSchema类
1。xsd基礎(chǔ):
類型:xs:integer;?? xs:positiveInteger;(>0的整數(shù));??? xs:nonPositiveInteger;(<=0的整數(shù));
??????? xs:Bool;??? xs:string
??????? xs:dateTime;(日+時);?????? xs:date;(日);?????????? xs:time;(時);
<xs:schema....>
<xs:complexType name="autotype">------2級
?? <xs:sequence>
???????? <xs:element name="name" type="xs:string"/>-----1級
??? </xs:sequence>
</xs:complexType>
<xs:complexType name="booktype">-----3級
?? <xs:sequence>?
???????? <xs:element name="typename" type="autotype"/>------應(yīng)用2級
??? </xs:sequence>
</xs:complexType>
<xs:element name="book" type="booktype"/>-----應(yīng)用3級
</xs:schema>
2。設(shè)計(jì)成XML模式
class Program
??? {
??????? [STAThread]
??????? static void Main(string[] args)
??????? {? XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
??????????? nsm.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
??????????? XmlSchema sche = new XmlSchema();
??????????? XmlSchemaComplexType cauth = new XmlSchemaComplexType();
??????????? cauth.Name = "author";
??????????? XmlSchemaSequence seqauth = new XmlSchemaSequence();
??????????? XmlSchemaElement ele = new XmlSchemaElement();
??????????? ele.Name = "name";
??????????? ele.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
??????????? seqauth.Items.Add(ele);
??????????? XmlSchemaElement eleage = new XmlSchemaElement();
??????????? eleage.Name = "age";
??????????? eleage.SchemaTypeName = new XmlQualifiedName("positiveInteger", "http://www.w3.org/2001/XMLSchema");
??????????? seqauth.Items.Add(eleage);
??????????? cauth.Particle = seqauth;
??????????? sche.Items.Add(cauth);????????????
??????????? sche.Compile(new ValidationEventHandler(valia));
??????????? sche.Write(Console.Out, nsm);
??????? }
}
個人總結(jié):
結(jié)果:
<?xml version="1.0" encoding="gb2312"?>
----------------xs:..........->xmlNamespaceManager.AddNamespace
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">-new XmlSchema??
<xs:complexType name="author">------------------new XmlSchemaComplexType
??? <xs:sequence>----------------------------------new XmlSchemaSequence
????? <xs:element name="name" type="xs:string"/>---new XmlSchemaElement
????? <xs:element name="age" type="xs:positiveInteger"/>------new XmlSchemaElement?
??? </xs:seqence>
? </xs:complexType>
</xs:schema>
?
轉(zhuǎn)自:http://www.cnblogs.com/winvay/articles/1321496.html
轉(zhuǎn)載于:https://www.cnblogs.com/zguoq2002/archive/2012/01/31/2332582.html
總結(jié)
以上是生活随笔為你收集整理的C#生成XSD规范,利用XmlSchema类的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 限制不能使用最近三次的历史密码
- 下一篇: WEB程序打包详解:(连接SQL2005