温伟的程序生活,一步一个脚印
自己会努力,做真正独一无二的温伟!无论前方有多难,我都不会放弃... 每一篇日志,都是我的积累,全是我的原创!

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)

posted on 2008-10-28 17:06  winvay  阅读(3937)  评论(1编辑  收藏  举报