是否可以在XML元素名称中允许使用字符? [英] Is it possible to allow chars in an XML element name?

查看:143
本文介绍了是否可以在XML元素名称中允许使用字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文本框,我将文本保存到xml文件。第一个文本框进入元素名称,第二个文本框进入值,所以我希望能够使用这些文本框中的任何字符,但我得到错误说字符''十六进制值0x20不能包含在名称中。一个文本框用于命名空间,另一个文本框用于值。我需要在名称中使用字符。我使用的是XDocument而不是XmlDocument



我尝试了什么:



i看了谷歌,但我找到的是如何删除chars不是如何允许他们。我按照它的方式尝试但是如果我输入字符然后它会抛出异常。

I have textboxes that i save the text to an xml file.The first textbox goes into the element name and the second goes into the value so I want to be able to use any chars in these textboxes but i get errors saying The character ' ' hexadecimal value 0x20 cannot be included in a name.the one textbox is used for the namespace and the other for the value.I need to allow chars in the name.I am using XDocument and not XmlDocument

What I have tried:

i have looked on Google but all i find is how to remove chars not how to allow them.I tried it the way it is but if i enter chars then it throws exceptions.

推荐答案

你可能在谈论CDATA部分。它们可用于存储您想要的任何文本信息,而无需担心转义字符。



Google:XML CDATA [< a href =https://www.google.com/search?source=hp&ei=LvtxW8OtBoLQ8AOzyxI&q=XML+CDATA&oq=XML+CDATA&gs_l=psy-ab.3..0l10.444.1419.0.1730 .10.8.0.0.0.0.277.1018.2-4.4.0..2..0 ... 1.1.64.psy-ab..6.4.1017.0..0i20i264k1.0.xNzf8BPycos和放大器;安全=主动和放大器; ssui =上target =_ blanktitle =New Window> ^ ]
You're probably talking about a CDATA section. They can be used to store any text information you want without having to worry about escaping characters.

Google: "XML CDATA"[^]


这篇关于是否可以在XML元素名称中允许使用字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆