C# XElement.读取符号和特殊国家字符时的加载错误
我在从XML文件读取符号时遇到问题:C# XElement.读取符号和特殊国家字符时的加载错误,c#,xml,xml-parsing,C#,Xml,Xml Parsing,我在从XML文件读取符号时遇到问题: XElement xmlElements = XElement.Load(Path_Xml_Data_File); 当出现以下情况时,我会收到错误: <Name>Patrick & Phill</Name> Error: Name cannot begin with the ' ' character, hexadecimal value 0x20. Xml.XmlException) A System.Xml.XmlEx
XElement xmlElements = XElement.Load(Path_Xml_Data_File);
当出现以下情况时,我会收到错误:
<Name>Patrick & Phill</Name>
Error: Name cannot begin with the ' ' character, hexadecimal value 0x20. Xml.XmlException) A System.Xml.XmlException was thrown: "Name cannot begin with the ' ' character
Patrick&Phill
错误:名称不能以“”字符、十六进制值0x20开头。Xml.XmlException)引发System.Xml.XmlException:“名称不能以“”字符开头
或使用特殊葡萄牙语字符:
<Extra>Direcção Assistida</Extra> (= <Extra>Direcção Assistida</Extra>)
Error: Reference to undeclared entity 'ccedil'
Direcç;ã;o Assistida(=Direcço Assistida)
错误:引用未声明的实体“ccedil”
知道如何解决这个问题吗?恐怕您正在处理格式错误的XML 要表示符号AND,加载的数据应使用“&;“实体 ç;(ç)和ã;(ã)命名实体不是XML标准的一部分,它们更常见于HTML中(尽管它们可以通过使用DTD添加到XML中) 您可以先使用HtmlTidy整理数据,也可以编写一些东西将空的符号转换为传入文件上的实体 例如:
public string CleanUpData(string data)
{
var r = new Regex(@"&\s");
string output = r.Replace(data, "& ");
output = output.Replace("ç", "ç");
output = output.Replace("ã", "ã");
return output;
}
您好,谢谢,但是在我加载XElement.xml?XElement.Parse(cleanUpdatea(File.ReadAllText(Path_xml_Data_File)))之前,我怎么做呢;