2

例如。这些 xml 标签是否可以接受。

<xml>
<3333>abc</3333>
<ab#$3>def</ab#$3>
</xml>

我的问题是我可以创建整数值标签或带有特殊字符的标签吗?

我试过这个

FileStream fs = new FileStream((filename), FileMode.Append);
XmlWriter w = XmlWriter.Create(fs);
w.WriteStartElement("3454");

并得到以下错误 {System.ArgumentException: Invalid name character in '3454'. The '3' character, hexadecimal value 0x33, cannot be included in a name. at System.Xml.XmlWellFormedWriter.CheckNCName(String ncname) at System.Xml.XmlWellFormedWriter.WriteStartElement(String prefix, String localName, String ns) at System.Xml.XmlWriter.WriteStartElement(String localName) at WindowsFormsApplication1.Form1.fn_setMapping(SqlString keyString, SqlString column, SqlString value)

谢谢你

4

1 回答 1

5

XML 元素名称不能以数字开头,因此<3333>无效。

至于哪些特殊字符是有效的......请参阅元素名称规范

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)*

有效名称应以 a 开头,NameStartChar后跟任意数量的NameChar.

于 2012-05-10T13:17:52.547 回答