This question already has answers here:
The ':' character, hexadecimal value 0x3A, cannot be included in a name

(6 个回答)



XmlWriter The ':' character, hexadecimal value 0x3A, cannot be included in a name

(1 个回答)


8年前关闭。




我正在使用 VS2010、C#、.net 和 xmlWriter 创建符合 HL7 CAT-1 规范的 xml 文档。必须在文档中创建一个属性“sdtc:ValueSet”。由于字符“:”无效,我无法写入此属性名称。

这是实际的代码行:
writer.WriteAttributeString("sdtc:valueSet", "OID value");

有没有人有创建属性的解决方案,如图所示?

继续研究,但决定发布这个问题,希望快速找到解决方案。

这个问题被标记为重复,我在争论是错误的。现有响应引用了编写元素或使用 LINQ。该问题使用 xmlWriter 明确说明了 Attribute。一位响应者建议使用重载的 WriteAttributeString 方法,该方法
解决了这个问题。

最佳答案

您使用了错误的 WriteAttributeString Method 重载。使用 the one 允许您指定前缀和 XML 命名空间:

writer.WriteAttributeString("sdtc", "valueSet", "urn:hl7-org:sdtc", "OID value");

关于c# - ':' 字符,十六进制值 0x3A,不能包含在名称中。"},我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17116424/

10-13 07:45