1。xsd基礎:
類型:xs:integer; xs:positiveInteger;(>0的整數); xs:nonPositiveInteger;(<=0的整數);
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"/>------應用2級
</xs:sequence>
</xs:complexType>
<xs:element name="book" type="booktype"/>-----應用3級
</xs:schema>
2。設計成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);
}
}
個人總結:
結果:
<?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>
XmlSchema.Items.Add(XmlSchemaComplexType)
XmlSchemaComplexType.Particle = XmlSchemaSequence
XmlSchemaSequence.Add(XmlSchemaElement)
轉載位址: http://www.cnblogs.com/winvay/articles/1321496.html