我正在尝试为此XML构建一个小型验证
<adr>
<parameters>
<type><text>work</text></type>
<label><text>Simon Perreault 2875 boul. Laurier, suite D2-630 Quebec, QC, Canada G1V 2M2</text></label>
</parameters>
<pobox/>
<ext/>
<street>2875 boul. Laurier, suite D2-630</street>
<locality>Quebec</locality>
<region>QC</region>
<code>G1V 2M2</code>
<country>Canada</country>
</adr>
考虑到pobox
有两个属性cod
和region
,我对此DTD缺少什么?任何人都可以帮助我吗?
<?mlx version ="1.0"?>
<!DOCTYPE ADR [
<!ELEMENT ADR (PARAMETERS, POBOX, EXT, STREET, LOCALITY, REGION, CODE, COUNTRY)>
<!ELEMENT PARAMETERS (#PCDATA)>
<!ELEMENT POBOX (#PCDATA)>
<!ELEMENT EXT (#PCDATA)>
<!ELEMENT STREET (#PCDATA)>
<!ELEMENT LOCALITY (#PCDATA)>
<!ELEMENT REGION (#PCDATA)>
<!ELEMENT CODE (#PCDATA)>
<!ELEMENT COUNTRY (#PCDATA)>
<!ATTLIST POBOX COD CDATA #IMPLIED>
<!ATTLIST POBOX REGION CDATA #IMPLIED>
]>
答案 0 :(得分:0)
以下是我注意到的一些事情:
mlx
的含义,并且它被视为正常的处理指令。adr
,则不应将其声明为ADR
。parameters
有两个子元素,但声明只允许#PCDATA
。ATTLIST
声明,那就更容易阅读。以下是您的DTD的更新版本:
<?xml version="1.0"?>
<!DOCTYPE adr [
<!ELEMENT adr (parameters, pobox, ext, street, locality, region, code, country)>
<!ELEMENT parameters (type, label)>
<!ELEMENT type (text)>
<!ELEMENT label (text)>
<!ELEMENT text (#PCDATA)>
<!ELEMENT pobox (#PCDATA)>
<!ATTLIST pobox
cod CDATA #IMPLIED
region CDATA #IMPLIED>
<!ELEMENT ext (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT locality (#PCDATA)>
<!ELEMENT region (#PCDATA)>
<!ELEMENT code (#PCDATA)>
<!ELEMENT country (#PCDATA)>
]>