<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Movie" targetNamespace="http://tempuri.org/" elementFormDefault="qualified" xmlns="http://tempuri.org/" xmlns:mstns="http://tempuri.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema">  
  <xs:complexType name="Ticket">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" name="Tick" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" name="TicketString" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" name="RoomName" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" name="FilmName" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" name="ShowTime" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" name="IsTrue" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" name="SellingPrice" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" name="lpTime" type="xs:string" />
      <xs:element minOccurs="1" maxOccurs="1" name="ID" type="xs:int" />
    </xs:sequence>
  </xs:complexType>  <xs:element name="GetTicketResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="1" name="GetTicketResult" type="Ticket" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
上面是要生成的XSD文件
其中生成Ticket的代码如下            XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
            nsm.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
            XmlSchemaComplexType cauth = new XmlSchemaComplexType();
            cauth.Name = "Ticket";
            XmlSchemaSequence seqauth = new XmlSchemaSequence();
            XmlSchemaElement eleage = CreatXmlSchemaElementNorm(0, 1, "Tick", "xs:string");
            seqauth.Items.Add(eleage);
            eleage = CreatXmlSchemaElementNorm(0, 1, "TicketString", "xs:string");
            seqauth.Items.Add(eleage);
            eleage = CreatXmlSchemaElementNorm(0, 1, "RoomName", "xs:string");
            seqauth.Items.Add(eleage);
            eleage = CreatXmlSchemaElementNorm(0, 1, "FilmName", "xs:string");
            seqauth.Items.Add(eleage);
            eleage = CreatXmlSchemaElementNorm(0, 1, "ShowTime", "xs:string");
            seqauth.Items.Add(eleage);
            eleage = CreatXmlSchemaElementNorm(0, 1, "IsTrue", "xs:string");
            seqauth.Items.Add(eleage);
            eleage = CreatXmlSchemaElementNorm(0, 1, "SellingPrice", "xs:string");
            seqauth.Items.Add(eleage);
            eleage = CreatXmlSchemaElementNorm(0, 1, "lpTime", "xs:string");
            seqauth.Items.Add(eleage);
            eleage = CreatXmlSchemaElementNorm(1, 1, "ID", "xs:int");
            seqauth.Items.Add(eleage);
            cauth.Particle = seqauth;
            sche.Items.Add(cauth);可是却不知道GetTicketResponse这一个要如何生成
我写了一部份            XmlSchemaElement xse = new XmlSchemaElement();
            xse.Name = "GetTicketResponse";
            XmlSchemaComplexType cauth = new XmlSchemaComplexType();
            XmlSchemaSequence seqauth = new XmlSchemaSequence();
            XmlSchemaElement eleage = CreatXmlSchemaElementNorm(0, 1, "GetTicketResult", "Ticket");
            seqauth.Items.Add(eleage);
            cauth.Particle = seqauth;不知道如何把cauth放到xse里面懂的教下我好吗?

解决方案 »

  1.   

    使用XmlDocumenthttp://www.whwish.cn/bbs/dispbbs.asp?boardid=5&Id=5401
      

  2.   

    设置
    xse.SchemaType = cauth;
      

  3.   

    所有C#代码如下:using System;
    using System.Xml;
    using System.Xml.Schema;
    class xmls
    {
    public static void Main()
    {
     XmlSchema schema = new XmlSchema();
    XmlSchemaComplexType newcomplexType = new XmlSchemaComplexType();
          newcomplexType.Name="Ticket";  
     XmlSchemaSequence newseqauth = new XmlSchemaSequence(); XmlSchemaElement eletwo=new XmlSchemaElement();
    newseqauth.Items.Add(eletwo);
    eletwo.Name="Tick";
    eletwo.MinOccurs = 0;
            eletwo.MaxOccursString = "1";
    eletwo.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
    XmlSchemaElement eletwo1=new XmlSchemaElement();
    newseqauth.Items.Add(eletwo1);
    eletwo1.Name="TicketString";
    eletwo1.MinOccurs = 0;
            eletwo1.MaxOccursString = "1";
    eletwo.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
    XmlSchemaElement eletwo2=new XmlSchemaElement();
    newseqauth.Items.Add(eletwo2);
    eletwo2.Name="RoomName";
    eletwo2.MinOccurs = 0;
            eletwo2.MaxOccursString = "1";
    eletwo2.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
    XmlSchemaElement eletwo3=new XmlSchemaElement();
    newseqauth.Items.Add(eletwo3);
    eletwo3.Name="FilmName";
    eletwo3.MinOccurs = 0;
            eletwo3.MaxOccursString = "1";
    eletwo3.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
    XmlSchemaElement eletwo4=new XmlSchemaElement();
    newseqauth.Items.Add(eletwo4);
    eletwo4.Name="ShowTime";
    eletwo4.MinOccurs = 0;
            eletwo4.MaxOccursString = "1";
    eletwo4.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
    XmlSchemaElement eletwo5=new XmlSchemaElement();
    newseqauth.Items.Add(eletwo5);
    eletwo5.Name="IsTrue";
    eletwo5.MinOccurs = 0;
            eletwo5.MaxOccursString = "1";
    eletwo5.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
    XmlSchemaElement eletwo6=new XmlSchemaElement();
    newseqauth.Items.Add(eletwo6);
    eletwo6.Name="SellingPrice";
    eletwo6.MinOccurs = 0;
            eletwo6.MaxOccursString = "1";
    eletwo6.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
    XmlSchemaElement eletwo7=new XmlSchemaElement();
    newseqauth.Items.Add(eletwo7);
    eletwo7.Name="lpTime";
    eletwo7.MinOccurs = 0;
            eletwo.MaxOccursString = "1";
    eletwo7.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
    XmlSchemaElement eletwo8=new XmlSchemaElement();
    newseqauth.Items.Add(eletwo8);
    eletwo8.Name="ID";
    eletwo8.MinOccurs = 1;
            eletwo8.MaxOccursString = "1";
    eletwo8.SchemaTypeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");
             newcomplexType.Particle = newseqauth;
             schema.Items.Add(newcomplexType);
     XmlSchemaElement elementCat = new XmlSchemaElement();
            schema.Items.Add(elementCat);
            elementCat.Name = "GetTicketResponse";    
    XmlSchemaComplexType complexType = new XmlSchemaComplexType();      
     XmlSchemaSequence seqauth = new XmlSchemaSequence();
     XmlSchemaElement eleone=new XmlSchemaElement();
    seqauth.Items.Add(eleone);
    eleone.Name="GetTicketResult";
    eleone.MinOccurs = 0;
            eleone.MaxOccursString = "1";
    eleone.SchemaTypeName = new XmlQualifiedName("Ticket", "http://www.w3.org/2001/XMLSchema");
                   complexType.Particle = seqauth;
             elementCat.SchemaType = complexType;
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
           nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
            schema.Write(Console.Out,nsmgr);}
    }