在 XML DTD 的枚举属性值中插入特殊字符,如“#”
Inserting special characters like "#" in enumerated attribute values in XML DTD
我有以下 xml.dtd
文件
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT aliens (alien+,alienTesting)>
<!ELEMENT alien (name,from,middleName?)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT middleName (#PCDATA)>
<!--defining element attributes -->
<!ATTLIST alien aid ID #REQUIRED>
<!ATTLIST alien bioType CDATA #IMPLIED>
<!ATTLIST alien lang (Java|C|Python) "Java">
<!ELEMENT alienTesting (alienT*)>
<!ELEMENT alienT (#PCDATA)>
这是 xml
文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE aliens SYSTEM "AleinDTD.dtd">
<aliens>
<alien aid="a01">
<name>Kasun </name>
<from>Northwest</from>
</alien>
<alien aid="a02">
<name>Madu</name>
<from>south</from>
</alien>
<alienTesting>
<alienT></alienT>
</alienTesting>
</aliens>
我要的是枚举属性中有Java
,C#
,Python
。
所以当我如下更改它时
<!ATTLIST alien lang (Java|C#|Python) "Java">
它给我一个错误
The enumerated type list must end with ')' in the "lang" attribute declaration
如何解决这个问题,提前致谢
恐怕不可能了。看看 XML Specification, §3.3.1 Attribute types, the enumerated values should be Nmtoken, where the characters allowed are listed here:
The ASCII symbols and punctuation marks, along with a fairly large group of Unicode symbol characters, are excluded from names because they are more useful as delimiters in contexts where XML names are used outside XML documents; providing this group gives those contexts hard guarantees about what cannot be part of an XML name. The character #x037E, GREEK QUESTION MARK, is excluded because when normalized it becomes a semicolon, which could change the meaning of entity references.
[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
大体上,您可以使用数字和字母(来自任何语言)、连字符、点、下划线 ,但不能使用 空格、# ( ) [ ] |
和其他标点符号。
我有以下 xml.dtd
文件
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT aliens (alien+,alienTesting)>
<!ELEMENT alien (name,from,middleName?)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT middleName (#PCDATA)>
<!--defining element attributes -->
<!ATTLIST alien aid ID #REQUIRED>
<!ATTLIST alien bioType CDATA #IMPLIED>
<!ATTLIST alien lang (Java|C|Python) "Java">
<!ELEMENT alienTesting (alienT*)>
<!ELEMENT alienT (#PCDATA)>
这是 xml
文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE aliens SYSTEM "AleinDTD.dtd">
<aliens>
<alien aid="a01">
<name>Kasun </name>
<from>Northwest</from>
</alien>
<alien aid="a02">
<name>Madu</name>
<from>south</from>
</alien>
<alienTesting>
<alienT></alienT>
</alienTesting>
</aliens>
我要的是枚举属性中有Java
,C#
,Python
。
所以当我如下更改它时
<!ATTLIST alien lang (Java|C#|Python) "Java">
它给我一个错误
The enumerated type list must end with ')' in the "lang" attribute declaration
如何解决这个问题,提前致谢
恐怕不可能了。看看 XML Specification, §3.3.1 Attribute types, the enumerated values should be Nmtoken, where the characters allowed are listed here:
The ASCII symbols and punctuation marks, along with a fairly large group of Unicode symbol characters, are excluded from names because they are more useful as delimiters in contexts where XML names are used outside XML documents; providing this group gives those contexts hard guarantees about what cannot be part of an XML name. The character #x037E, GREEK QUESTION MARK, is excluded because when normalized it becomes a semicolon, which could change the meaning of entity references.
[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
大体上,您可以使用数字和字母(来自任何语言)、连字符、点、下划线 ,但不能使用 空格、# ( ) [ ] |
和其他标点符号。