以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  我想探讨的几个Schema中写attribute的问题???[求助]  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=23338)


--  作者:RainbowBoy
--  发布时间:10/20/2005 3:19:00 AM

--  我想探讨的几个Schema中写attribute的问题???[求助]
如果我的XML文件中一个元素(element)带属性,同时又有内容,那Shema怎样处理呢??

比如说像这样:

<speed unit="GHz">725-1.5</speed>
<cache unit="MB">2</cache>

"unit"这是个属性。假如没有属性的话一般写成下面这样,

我是用"ref"写的,也就是把每一个元素都单列出来了:
比如这个"speed"是包括在"processore" 中的,就先写

<xsd:element name="processor">
  <xsd:sequence>
     <xsd: element ref="speed"/>  
      <.............................../>
     <.............................../>
  </xsd:sequence>
</xsd:element>

然后在单写每一个,比如:
<xsd:element name="speed">
  <xsd:singletype>
      <xsd:restriction base="decimal">
      <xsd:minInclusive ="...."  maxInclusive="....">
      </xsd:restriction>
  </xsd:singletype>
</xsd:element>

我知道含属性的元素话应用<complextype>,可我想同时限制元素内容的范围,比如最大和最小数不超过多少,可这样该怎办呢?还有处理器的速率写出来是前面比后面大,比如说:725-1.60GHz,这还能用minInclusive和maxInclusive吗??minInclusive是不是应该比maxInclusive定义的数值小呀???

还有"unit"是重复的,当然往下可能还要有重复出现,所以 这样的属性重复的话怎样办??


--  作者:xlx
--  发布时间:10/22/2005 9:31:00 PM

--  
才刚看完DTD,对Shema不太熟悉.不好意思.帮不了你.
--  作者:ITer
--  发布时间:11/2/2005 2:48:00 PM

--  
先为speed的content定义一个简单类型
<simpleType name="speedST">
  <restriction base="string">
     <pattern value="\d{3}-\d\.\d{2}">
  </restriction>
</simpleType>
然后定义speed的复杂类型
<complexType name="speed">
  <simpleContent>
    <extension>
       <attribute name="unit" type="string">
    </extension>
  </simpleContent>
</complexType>

min应该比max小因为min表示的是最小值而max是最大值
对于重复的unit属性,你可以定义一个全局的属性,然后在重复使用的地方引用他


--  作者:ITer
--  发布时间:11/2/2005 2:51:00 PM

--  
以下是引用ITer在2005-11-2 14:48:00的发言:
先为speed的content定义一个简单类型
<simpleType name=&quot;speedST&quot;>
   <restriction base=&quot;string&quot;>
      <pattern value=&quot;\d{3}-\d\.\d{2}&quot;>
   </restriction>
</simpleType>
然后定义speed的复杂类型
<complexType name=&quot;speed&quot;>
   <simpleContent>
     <extension>
        <attribute name=&quot;unit&quot; type=&quot;string&quot;>
     </extension>
   </simpleContent>
</complexType>

min应该比max小因为min表示的是最小值而max是最大值
对于重复的unit属性,你可以定义一个全局的属性,然后在重复使用的地方引用他


不好意思有个地方写错了,应该是这样
<complexType name="speed">
  <complexContent>
    <extension base="speedST">
        ....
    </extension>
  </comlexContent>
</complexType>


--  作者:kuloyy
--  发布时间:9/8/2007 12:07:00 AM

--  
<Price Days="10">2500.00</Price>
--  作者:ldj_11
--  发布时间:9/19/2009 10:18:00 PM

--  
<qwe>
  <item name="存货分类">坑代</item>
<item name="原材料项目辅助核算">消耗</item>
</qwe>


这种情况如何schema?


--  作者:hexun831012
--  发布时间:9/20/2009 4:08:00 PM

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