2010-03-25 64 views
0

我需要創建程序,創建一個XML架構如下圖所示使用System.Xml.XmlSchema命名空間C#幫助:添加一個複雜類型的主要的XmlSchema

我使用XmlSchemaComplexType到的MyString和MyInteger但我可以」 t似乎找到了一種方法來分別設置擴展名爲base string和int。

任何指導,非常感謝......感謝

<?xml version="1.0" encoding="utf-8" ?> 
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:complexType name="MyString"> 
     <xs:simpleContent> 
      <xs:extension base="xs:string"> 
       <xs:attribute name="modified" type="xs:boolean" /> 
      </xs:extension> 
     </xs:simpleContent> 
    </xs:complexType> 
    <xs:complexType name="MyInteger"> 
     <xs:simpleContent> 
      <xs:extension base="xs:int"> 
       <xs:attribute name="modified" type="xs:boolean" /> 
      </xs:extension> 
     </xs:simpleContent> 
    </xs:complexType> 
    <xs:element name="data"> 
     <xs:complexType> 
      <xs:sequence> 
       <xs:element name="row"> 
        <xs:complexType> 
         <xs:sequence> 
          <xs:element name="order_id" type="MyInteger" /> 
          <xs:element name="order_status" type="MyString" /> 
         </xs:sequence> 
        </xs:complexType> 
       </xs:element> 
      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 
</xs:schema> 

回答

1

我相信這樣的事情應該做的伎倆:

// <xs:simpleContent> 
XmlSchemaSimpleContent simpleContent = new XmlSchemaSimpleContent(); 

// <xs:extension base="xs:string"> 
XmlSchemaSimpleContentExtension simpleContent_extension = 
    new XmlSchemaSimpleContentExtension(); 

simpleContent_extension.BaseTypeName = 
    new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); 

看到的this page上下文底部的例子。

+0

感謝DanM,只有更多額外的步驟XmlSchemaComplexType complexType = new XmlSchemaComplexType(); complexType.ContentModel = simpleContent; – G33kKahuna 2010-03-30 21:30:44