Can XML attributes have spaces?

时间秒杀一切 提交于 2021-02-07 12:07:28

问题


I'm creating a DTD for an xml document. I have an Enumerated attribute for an xml element. My question is: Can the attribute Type have spaces?

eg:

  <!ELEMENT Link (#PCDATA)>
  <!ATTLIST Link Type (Amendment|Reference|Superseded|Modified|
  Corrigendum|Corresponds|Endorsement|Equivalent|Identical|Modified|
  Not Equivalent|Note taken of|Related|Similar) "Reference">

So what I would like is:

  <Link Type="Not Equivalent" \>

But that seems to barf.

Is there some magic voodoo I need to do for spaces? Or is it just tough luck?

I looked in a few spots but couldn't see any reference

Thanks!

Update

Sorry - when I say barf, I mean that when I try to validate the document (Eg Open it in a web browser) I get an error message: Invalid character found in ATTLIST enumeration. Error processing resource 'file:///C:/myxmldocument.xml'. ...


回答1:


The short answer is no. Xml attributes are name tokens and name tokens cannot contain spaces. The relevant specs are linked:

Attributes

Attribute Types (see NotationType)

Names (See 4a - NameChar)

The invalid character is the space. You can use '.' or '-' as a separator if you like.



来源:https://stackoverflow.com/questions/2277297/can-xml-attributes-have-spaces

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!