为什么以下代码不正确? XMLspy在元素employee
中发现错误<!ELEMENT personnel (contractor*,employee*,partner*)+ >
<!ELEMENT contractor (info)>
<!ELEMENT employee(info)>
<!ATTLIST info lname CDATA #REQUIRED fname CDATA #REQUIRED hiredate CDATA #REQUIRED firedate CDATA #REQUIRED>
答案 0 :(得分:1)
employee
后需要一个空格。
info
元素也未定义。
如果你要做的是获取contractor
和employee
上的属性,那么就这样做了:
<!ELEMENT personnel (contractor*, employee*, partner*)+ >
<!ELEMENT contractor EMPTY>
<!ELEMENT employee EMPTY>
<!ATTLIST contractor lname CDATA #REQUIRED fname CDATA #REQUIRED hiredate CDATA #REQUIRED firedate CDATA #REQUIRED>
<!ATTLIST employee lname CDATA #REQUIRED fname CDATA #REQUIRED hiredate CDATA #REQUIRED firedate CDATA #REQUIRED>
根据上述DTD,这是有效的:
<personnel>
<employee lname="Foo" fname="Bar" firedate="1" hiredate="2"/>
<contractor lname="Foo" fname="Bar" firedate="1" hiredate="2"/>
</personnel>
或者你可以像这样分享属性声明:
<!ENTITY % shared "lname CDATA #REQUIRED fname CDATA #REQUIRED hiredate CDATA #REQUIRED firedate CDATA #REQUIRED">
<!ELEMENT personnel (contractor*, employee*, partner*)+ >
<!ELEMENT contractor EMPTY>
<!ELEMENT employee EMPTY>
<!ATTLIST contractor %shared;>
<!ATTLIST employee %shared;>
这样,如果您需要更改属性列表,则contractor
和employee
都会更改。