English 中文(简体)
在XML中使用
原标题:Using - in XML element name
  • 时间:2009-09-25 17:05:11
  •  标签:

在XML要素名称中使用hyphen -?

e.g.

<rank-type>Rank</rank-type>
最佳回答

如文科和黑客所轻易指出的那样,答案是正确的。

Yes, dashes are granted in name, 无论内容名称还是属性名称。 但是,<<>a dash>cannot是上的第一个特性。

W3C标准将姓名定义为: (第2.3节)

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]
NameChar  ::=   NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
Name  ::= NameStartChar (NameChar)*

忽略ASCII的各种延伸特征和双重特征(从辛加税定义中的“标志”开始),名称必须用上下或下级的案件信(A-Z)、上校(:)或强调。 起始性之后的特性,即如果名称不是单一特性,则可以是有效开端特性和(或)任何数字(0-9)、著名的 d(-)和 do(......)

正如其他答复中指出的那样,如果可能的话,最好避免某些特性,即使这些特性可能是合法的,以免我们面临与不同教区和不同阶层之间执行某些具体困难的风险。

W3C本身含蓄地证明使用木单,因为木she在XSL中广泛使用。

问题回答

这不是名词,而是名词。

无论如何,只要名称不从该名称开始,就支持该名词的属性和元件名称(并注明;foo>不是有效元素名称)。

某些软件可能会在它上cho,但警告是这样。 如果你不得不使用这种软件,设法找到更好的软件,或使其开发商适当支持XML光谱。

W3CSchools (polemic) recommendations

Make names descriptive. Names with an underscore separator are nice: <first_name>, <last_name>.

Names should be short and simple, like this: <book_title> not like this: <the_title_of_the_book>.

Avoid "-" characters. If you name something "first-name," some software may think you want to subtract name from first.

Avoid "." characters. If you name something "first.name," some software may think that "name" is a property of the object "first."

Avoid ":" characters. Colons are reserved to be used for something called namespaces (more later).

XML documents often have a corresponding database. A good practice is to use the naming rules of your database for the elements in the XML documents.

象Eòá这样的非英语信在XML中完全合法,但如果你的软件供应商不支持这些问题,则会发现问题。

是的。 但是,你的榜样显示了要素名称,而不是归属。 同样有效。





相关问题
热门标签