以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  请问如何通过Schema设计使得元素只有属性值而没有没内容?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=44605)


--  作者:ainogod
--  发布时间:3/29/2007 4:21:00 PM

--  请问如何通过Schema设计使得元素只有属性值而没有没内容?
谢谢指教
--  作者:gemingke
--  发布时间:3/30/2007 2:11:00 PM

--  
可以,有两种方式

第一种,只设定元素包含属性,不包含内容,举例如下

<xs:element name="A1">
  <xs:complexType>
   <xs:attribute name="cd" use="optional">
    <xs:simpleType>
     <xs:restriction base="xs:string"/>
    </xs:simpleType>
   </xs:attribute>
  </xs:complexType>
 </xs:element>

第二种,使用nillable属性,这样元素也可包含内容,举例如下

<xs:element name="A2" nillable="true">
  <xs:complexType>
   <xs:simpleContent>
    <xs:extension base="xs:string">
     <xs:attribute name="dc" type="dc" use="optional"/>
    </xs:extension>
   </xs:simpleContent>
  </xs:complexType>
 </xs:element>
 <xs:simpleType name="dc">
  <xs:restriction base="xs:string"/>
 </xs:simpleType>


--  作者:ainogod
--  发布时间:3/31/2007 1:06:00 PM

--  
thanks

W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms