• XML文件的DTD编写


    <?xml version="1.0" encoding="UTF-8" ?> 
    
    <!--DTD外部引用:--> 
    <!DOCTYPE note SYSTEM "note.dtd">  <!--外联文件可以不写申明,如果写必须要有encoding="UTF-8" SYSTEM代表系统内部调用,后面是相对路径-->
    
    <!--DTD内嵌引用 -->
    
    <!DOCTYPE note [
      <!ELEMENT note (to?,from+,heading,body)>  <!-- +至少一次 *一次或多次 ?0或1次 默认一次 |或者-->
      <!ELEMENT to      (#PCDATA)>  <!-- 注意, to后面一定加空格 -->
      <!ELEMENT from    (#PCDATA)>
      <!ELEMENT heading (#PCDATA)>
      <!ELEMENT body    (#PCDATA)>
      <!ATTLIST to copy CDATA #IMPLIED>
    ]>
    
    <!-- 
    添加属性:<!ATTLIST 元素名称 属性名称 属性类型 默认值>
    常用属性: CDATA   值为字符数据 (character data) 
    属性必须添加 约束:
    REQUIRED 属性值是必需的 
    #IMPLIED 属性不是必需的 
    #FIXED value 属性值是固定的 
     -->
    
    
    
    <!-- 对应此约束的XML文件 -->
    
    <note>
      <to>George</to> 
      <from>John</from>
      <heading>Reminder</heading>
      <body>Don't forget the meeting!</body>
    </note> -->
    
    
    
    <!-- DTD示例 -->
    
     <!DOCTYPE students[
        <!ELEMENT students (student)>
        <!ELEMENT student (#PCDATA)>
        <!ELEMENT name (#PCDATA)>
        <!ELEMENT age (#PCDATA)>
        <!ELEMENT addr (#PCDATA)>
    ]>
    
    <!DOCTYPE book[
        <!ELEMENT book (name,price,date,author)> 
        <!ELEMENT name (#PCDATA)>
        <!ELEMENT price (#PCDATA)>
        <!ELEMENT date (#PCDATA)>
        <!ELEMENT author (#PCDATA)>
    ]>
    
    
    <!-- 一份XML文件中只能有一个DTD约束,不然会报错:Already seen doctype. -->
    
    <!-- 示例1 -->
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE TVSCHEDULE [
    
    <!ELEMENT TVSCHEDULE (CHANNEL+)>
    <!ELEMENT CHANNEL (BANNER,DAY+)>
    <!ELEMENT BANNER (#PCDATA)>
    <!ELEMENT DAY (DATE,(HOLIDAY|PROGRAMSLOT+)+)>
    <!ELEMENT HOLIDAY (#PCDATA)>
    <!ELEMENT DATE (#PCDATA)>
    <!ELEMENT PROGRAMSLOT (TIME,TITLE,DESCRIPTION?)>
    <!ELEMENT TIME (#PCDATA)>
    <!ELEMENT TITLE (#PCDATA)> 
    <!ELEMENT DESCRIPTION (#PCDATA)>
    
    <!ATTLIST TVSCHEDULE NAME CDATA #REQUIRED>
    <!ATTLIST CHANNEL CHAN CDATA #REQUIRED>
    <!ATTLIST PROGRAMSLOT VTR CDATA #IMPLIED>
    <!ATTLIST TITLE RATING CDATA #IMPLIED>
    <!ATTLIST TITLE LANGUAGE CDATA #IMPLIED>
    
    ]>
    
    <TVSCHEDULE NAME="中国电视报">
        <CHANNEL CHAN="cctv-2">
            <BANNER>江苏卫视</BANNER>
            <DAY>
                <DATE>2018-3-2</DATE>
                <PROGRAMSLOT>
                    <TIME>20:00</TIME>
                    <TITLE>春晚</TITLE>
                </PROGRAMSLOT>
            </DAY>
        </CHANNEL>
    </TVSCHEDULE>
    
    <!-- 示例2 -->
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE NEWSPAPER [ 
    
    <!ELEMENT NEWSPAPER (ARTICLE+)>
    <!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)>
    <!ELEMENT HEADLINE (#PCDATA)>
    <!ELEMENT BYLINE (#PCDATA)>
    <!ELEMENT LEAD (#PCDATA)>
    <!ELEMENT BODY (#PCDATA)>
    <!ELEMENT NOTES (#PCDATA)> 
    
    <!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
    <!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
    <!ATTLIST ARTICLE DATE CDATA #IMPLIED>
    <!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
    
    <!ENTITY NEWSPAPER "Vervet Logic Times">   <!-- 实体引用 -->
    <!ENTITY PUBLISHER "Vervet Logic Press">
    <!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">
    
    ]>
    <NEWSPAPER>
        <ARTICLE AUTHOR="PIKAQIU">
        <HEADLINE>2018新年第一场雪</HEADLINE>
        <BYLINE>SEU学生会</BYLINE>
        <LEAD>新年报道</LEAD>
        <BODY>XXXXXXX</BODY>
        <NOTES>(宣传组报道)</NOTES>
        </ARTICLE>
        
    </NEWSPAPER>
  • 相关阅读:
    poj 1860 Currency Exchange(最短路径的应用)
    poj 2965 The Pilots Brothers' refrigerator
    zoj 1827 the game of 31 (有限制的博弈论)
    poj 3295 Tautology (构造法)
    poj 1753 Flip Game(枚举)
    poj 2109 (贪心)
    poj 1328(贪心)
    Qt 对单个控件美化
    Qt 4基础
    Bash Shell
  • 原文地址:https://www.cnblogs.com/pikaqiucode/p/8242830.html
Copyright © 2020-2023  润新知