以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  [color=#FF0000]这个问题已经找了好多都没有解决!在子元素中添加属性但是这个元素还要有值 怎么写谢谢![/color]  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=45747)


--  作者:迷惘
--  发布时间:4/20/2007 6:33:00 PM

--  [color=#FF0000]这个问题已经找了好多都没有解决!在子元素中添加属性但是这个元素还要有值 怎么写谢谢![/color]
这个问题已经找了好多都没有解决
在子元素中添加属性但是这个元素还要有值 怎么写谢谢!

<?xml version="1.0" encoding="UTF-8"?>
<Tours xmlns="http://www.zkvod.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zkvod.com
C:\Users\迷惘\Desktop\Inventory_System.xsd">
 <Operator>
  <Name></Name>
  <Name></Name>
  <Email></Email>
  <Email></Email>
 </Operator>
 <Tour>
  <Code></Code>
  <Resort></Resort>
  <Facilities>
   <Facility></Facility>
   <Facility></Facility>
  </Facilities>
  <Price df="2">sd</Price> 
</Tour>
</Tours>

这个Price 怎么实现有属性还有值


--  作者:gemingke
--  发布时间:4/21/2007 3:46:00 PM

--  
翻翻 老贴

我记得是用simpleContent做 扩展


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

--  
先给一个xml文档的片断:
    <货物价格 单位="元">5670.00</货物价格>

该片断的schema如下:
<xs:element name="货物价格">
  <xs:complexType>
   <xs:simpleContent>
    <xs:extension base="货物价格Type">
     <xs:attribute name="单位" use="required" fixed="元"/>
    </xs:extension>
   </xs:simpleContent>
  </xs:complexType>
</xs:element>
<xs:simpleType name="货物价格Type">
  <xs:restriction base="xs:decimal">
   <xs:minInclusive value="0"/>
   <xs:totalDigits value="10"/>
   <xs:fractionDigits value="2"/>
  </xs:restriction>
</xs:simpleType>

如上所示,complexType里可以使用complexContent或simpleContent来对某种数据类型进行约束或扩展。上面的例子就是用simpleContent对“货物价格Type”进行扩展的实例。

这里要注意,complexContent的扩展或约束对象必须是complexType,simpleContent的扩展或约束对象必须是simpleType

还要注意一点,complexContent或simpleContent在进行约束或扩展时,都不可以使用刻面 (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDidits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern) ,刻面的使用必须是在simpleType的restriction下面


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