以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  各位大哥能不能提供一个XML文档并写出一下Schema啊?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=23402)


--  作者:zjw568
--  发布时间:10/21/2005 1:41:00 AM

--  各位大哥能不能提供一个XML文档并写出一下Schema啊?
各位大哥能不能提供一个XML文档并写出一下Schema啊?
谢谢各位大哥了
--  作者:孔南
--  发布时间:10/22/2005 6:37:00 PM

--  
XML-SPY 里面的例子, 刚刚学到, 自己比着写了一个 :)
强烈建议您也比着做一个, 立即就入门 schema 了! [反正我是这么想的]

<!--companyfirst.xml-->
以下内容为程序代码:

<?xml version="1.0" encoding="GB2312"?>
<Company xmlns="http://my-company.com/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://my-company.com/namespace
AddressFirst.xsd">
    <Address xsi:type="US-Address">
        <Name>US dependency</Name>
        <Street>Noble Ave</Street>
        <City>Dallas</City>
        <Zip>04812</Zip>
        <State>Texas</State>
    </Address>
    <Person Manager="true" Degree="PhD" Programmer="false">
        <First>Sim</First>
        <Last>Sum</Last>
        <PhpneExt>444</PhpneExt>
        <Email>smith@work.com</Email>
    </Person>
    <Person Manager="true" Degree="MA" Programmer="false">
        <First>zjw</First>
        <Last>568</Last>
        <PhpneExt>22</PhpneExt>
        <Email>zjw@568.com</Email>
    </Person>
    <Person Manager="true" Degree="BA" Programmer="false">
        <First>Fred</First>
        <Last>Smith</Last>
        <PhpneExt>22</PhpneExt>
        <Email>smith@work.com</Email>
    </Person>
</Company>


--  作者:孔南
--  发布时间:10/22/2005 6:39:00 PM

--  
<!--Addressfirst.xsd-->
以下内容为程序代码:

<?xml version="1.0" encoding="GB2312"?>
<xs:schema xmlns="http://my-company.com/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://my-company.com/namespace" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="Company">
        <xs:annotation>
            <xs:documentation>Root Element</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Address" type="AddressType"/>
                <xs:element ref="Person" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="AddressType">
        <xs:sequence>
            <xs:element name="Name" type="xs:string"/>
            <xs:element name="Street" type="xs:string"/>
            <xs:element name="City" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:simpleType name="US-State">
        <xs:restriction base="xs:string"/>
    </xs:simpleType>
    <xs:complexType name="US-Address">
        <xs:complexContent>
            <xs:extension base="AddressType">
                <xs:sequence>
                    <xs:element name="Zip" type="xs:positiveInteger"/>
                    <xs:element name="State" type="US-State"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="UK-Address">
        <xs:complexContent>
            <xs:extension base="AddressType">
                <xs:sequence>
                    <xs:element name="PostCode" type="xs:string"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:element name="Person">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="First" type="xs:string"/>
                <xs:element name="Last" type="xs:string"/>
                <xs:element name="Title" type="xs:string" minOccurs="0"/>
                <xs:element name="PhpneExt">
                    <xs:simpleType>
                        <xs:restriction base="xs:integer">
                            <xs:maxExclusive value="999"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element>
                <xs:element name="Email" type="xs:string"/>
            </xs:sequence>
            <xs:attribute name="Manager" type="xs:boolean" use="required"/>
            <xs:attribute name="Programmer" type="xs:boolean" use="optional"/>
            <xs:attribute name="Degree">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="BA"/>
                        <xs:enumeration value="MA"/>
                        <xs:enumeration value="PhD"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
</xs:schema>

--  作者:陌陌
--  发布时间:10/23/2005 2:05:00 PM

--  
对不起啊,大侠们,问一下,好像问题很白痴,所以不敢发表新话题:

xmlns="http://my-company.com/namespace"

这里面的地址到底是干什么的呀?
怎么用呢?
什么时候用什么地址啊?


--  作者:lovalift
--  发布时间:11/8/2005 12:24:00 PM

--  
<xs:annotation>
            <xs:documentation>Root Element</xs:documentation>
</xs:annotation>

请问annotation这个批注是干什么用的?

谢谢!


--  作者:future
--  发布时间:2/22/2006 11:18:00 PM

--  
命名空间,建议看看基础知识,呵呵
--  作者:hoteaw
--  发布时间:3/12/2006 6:44:00 PM

--  
再问: xmlns="http://my-company.com/namespace" 定义有什么原则吗? 是指向xsd集的目录?还是暗示指向namespace.xsd呢?
--  作者:メ冰枫ぱ雪
--  发布时间:3/19/2006 4:37:00 AM

--  
以下是引用陌陌在2005-10-23 14:05:00的发言:
对不起啊,大侠们,问一下,好像问题很白痴,所以不敢发表新话题:

  xmlns="http://my-company.com/namespace"

这里面的地址到底是干什么的呀?
怎么用呢?
什么时候用什么地址啊?


xmlns = xml namespace 命名空间~!

什么时候用什么地址? 不大理解。。


--  作者:daizemiao2006
--  发布时间:3/22/2006 12:18:00 PM

--  
能不能给出以上schema的实例文档啊?我基本也是按照那种格式写的,可是编写的实例文档有错啊!例如:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.hqu.edu.cn"
xmlns="http://www.hqu.edu.cn">
 <xsd:element name="订单" type="orderType"/>
 <xsd:complexType name="orderType">
  <xsd:sequence>
   <xsd:element name="订单号" type="xsd:positiveInteger"/>
   <xsd:element name="产品编码" type="xsd:positiveInteger"/>
  </xsd:sequence>
 </xsd:complexType>
</xsd:schema>
对应实例文档如下:
<?xml version="1.0" encoding="UTF-8" ?>
<订单 xmlns="http://www.hqu.edu.cn"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.hqu.edu.cn 3.25.xsd">
<订单号>123456789</订单号>
<产品编码>123456</产品编码>
</订单>
spy提示错误原因是:异常元素'定单号'在元素'定单'中,请问这是怎么回事啊?
--  作者:hgpimac
--  发布时间:3/24/2006 11:23:00 AM

--  
element中的complexType应该是匿名的
--  作者:zhaggliang610
--  发布时间:3/30/2006 8:51:00 PM

--  
对不起 我也是新手

--  作者:nonotoday
--  发布时间:4/3/2006 4:24:00 PM

--  
学习中。。。
--  作者:zieglar
--  发布时间:4/7/2006 9:43:00 AM

--  
<?xml version="1.0" encoding="UTF-8" ?>
<a1:订单 xmlns:a1="http://www.hqu.edu.cn"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.hqu.edu.cn 3.25.xsd">
<订单号>123456789</订单号>
<产品编码>123456</产品编码>
</a1:订单>

其实是你没有写前缀命名空间的问题~加上命名空间就木有问题鸟


--  作者:gemingke
--  发布时间:4/10/2006 1:03:00 PM

--  
以下是引用daizemiao2006在2006-3-22 12:18:00的发言:
能不能给出以上schema的实例文档啊?我基本也是按照那种格式写的,可是编写的实例文档有错啊!例如:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.hqu.edu.cn"
xmlns="http://www.hqu.edu.cn">
  <xsd:element name="订单" type="orderType"/>
  <xsd:complexType name="orderType">
   <xsd:sequence>
    <xsd:element name="订单号" type="xsd:positiveInteger"/>
    <xsd:element name="产品编码" type="xsd:positiveInteger"/>
   </xsd:sequence>
  </xsd:complexType>
</xsd:schema>
对应实例文档如下:
<?xml version="1.0" encoding="UTF-8" ?>
<订单 xmlns="http://www.hqu.edu.cn"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.hqu.edu.cn 3.25.xsd">
<订单号>123456789</订单号>
<产品编码>123456</产品编码>
</订单>
spy提示错误原因是:异常元素'定单号'在元素'定单'中,请问这是怎么回事啊?


异常元素的原因在于,element下面若有complexType,则element的type属性不可以有,而且,若compelxType上面有element,则complexType的name属性不可以有
--  作者:huangpengone
--  发布时间:4/10/2006 4:02:00 PM

--  

能不能给出以上schema的实例文档啊?我基本也是按照那种格式写的,可是编写的实例文档有错啊!例如:
<?xml version="1.0" encoding="UTF-8"?>
好像是
<?xml version="1.0" encoding="gb2312"?>



--  作者:gemingke
--  发布时间:4/10/2006 11:04:00 PM

--  
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="订单" >
  <xsd:complexType>
   <xsd:sequence>
    <xsd:element name="订单号">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
           <xsd:pattern value="[1-9]{9}"/>
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:element>
    <xsd:element name="产品编码" >
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
           <xsd:pattern value="[1-6]{6}"/>
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:element>

   </xsd:sequence>
  </xsd:complexType>
</xsd:schema>
对应实例文档如下:
<?xml version="1.0" encoding="UTF-8" ?>
<订单
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.hqu.edu.cn 3.25.xsd">
<订单号>123456789</订单号>
<产品编码>123456</产品编码>
</订单>


--  作者:gemingke
--  发布时间:4/10/2006 11:04:00 PM

--  
UTF-8也支持汉字
--  作者:awakening
--  发布时间:1/27/2007 3:57:00 AM

--  
Very good
--  作者:awakening
--  发布时间:1/27/2007 4:03:00 AM

--  
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:align="urn:ean.ucc:align:2"
xmlns:eanucc="urn:ean.ucc:2"
targetNamespace="urn:ean.ucc:align:2"
elementFormDefault="unqualified"
attributeFormDefault="unqualified"
version="2.0.2">

-------
Within a xsd file, multiple namespaces can be referred and used. uri definition, schema location format are hard to understand and write in a xml file.

<?xml version="1.0" encoding="UTF-8"?>
<align:conditionDocument creationDateTime="2007-01-18T16:32:52" documentStatus="COPY" lastUpdateDate="2007-01-18" xmlns:align="urn:ean.ucc:align:2" xmlns:eanucc="urn:ean.ucc:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="urn:ean.ucc:align:2 align/ConditionDocument.xsd urn:ean.ucc:2 ../common/ConditionDocumentImport.xsd ">

-----
above is an example of xml file according to xsd definition


--  作者:86版dingpin
--  发布时间:2/24/2008 7:49:00 PM

--  
我是菜鸟,可不可以把你的程序加上注释,优其是像
<Person Manager="true" Degree="PhD" Programmer="false">
Manager,Degree,Programmer是干什么的?
谢谢了!!!
--  作者:jinscott
--  发布时间:3/21/2008 10:44:00 PM

--  
刚写的练习,呵呵。看下吧,很容易得。

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2005 sp2 U (http://www.altova.com) by any (Ru-Board) -->
<!-- edited with XML Spy v4.4 alpha 1 U build Jun 28 2002 (http://www.xmlspy.com) by Altova (Altova) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tsd="http://namespaces.softwareag.com/tamino/TaminoSchemaDefinition" elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xs:element name="学生列表" type="学生列表类型"/>
 <xs:complexType name="学生列表类型">
  <xs:sequence>
   <xs:element name="学生信息" type="学生信息类型" maxOccurs="100"/>
  </xs:sequence>
 </xs:complexType>
 <xs:complexType name="学生信息类型">
  <xs:sequence>
   <xs:element name="学生姓名" type="学生姓名类型"/>
   <xs:element name="学生性别" type="学生性别类型"/>
   <xs:element name="学生生日" type="学生生日类型"/>
   <xs:element name="联系方式" type="联系方式类型"/>
   <xs:element name="学生分数" type="学生分数类型"/>
  </xs:sequence>
  <xs:attribute name="学生编号" type="学生编号类型"/>
 </xs:complexType>
 <xs:complexType name="联系方式类型">
  <xs:choice>
   <xs:element name="电话号码" type="电话号码类型"/>
   <xs:element name="家庭住址" type="家庭住址类型"/>
   <xs:element name="QQ号码" type="QQ号码类型"/>
  </xs:choice>
 </xs:complexType>
 <xs:simpleType name="学生编号类型">
  <xs:restriction base="xs:ID">
   <xs:pattern value="HK\d{4}"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="学生姓名类型">
  <xs:restriction base="xs:string">
   <xs:maxLength value="4"/>
   <xs:minLength value="2"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="学生性别类型">
  <xs:restriction base="xs:string">
   <xs:enumeration value="男"/>
   <xs:enumeration value="女"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="学生生日类型">
  <xs:restriction base="xs:date"/>
 </xs:simpleType>
 <xs:simpleType name="学生分数类型">
  <xs:restriction base="xs:int">
   <xs:maxInclusive value="100"/>
   <xs:minInclusive value="0"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="电话号码类型">
  <xs:restriction base="xs:string">
   <xs:pattern value="1[3,5]\d{9}"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="家庭住址类型">
  <xs:restriction base="xs:string">
   <xs:minLength value="4"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="QQ号码类型">
  <xs:restriction base="xs:string">
   <xs:pattern value="\d{5,9}"/>
  </xs:restriction>
 </xs:simpleType>
</xs:schema>


--  作者:melancholylp
--  发布时间:7/11/2008 11:34:00 PM

--  
最近老总要XML规范化...来学习了..嘿嘿
--  作者:tomcai
--  发布时间:12/29/2008 3:35:00 PM

--  
这东东是不是有专门的工具来编辑啊,DW行吗?现在看这代码明白了10%。。。学习ing...
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
140.625ms