Hello Everyone我正在通过解析器将数据作为xmlElemet读取
我收到错误比如..'\ b',十六进制值0x08,是一个无效字符
我读了这个字符串.. 感谢..
XElement xParser = null;
string sPwd = null;
string sKey1 = null;
string sKey2 = null;
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
string soutxml = "";
soutxml = encoding.GetString(sEncData);
xParser = XElement.Parse(soutxml);
IEnumerable<XElement> elemsValidations =
from el in xParser.Elements("EmailPwd")
select el;
foreach (XElement elemValidation in elemsValidations)
{
sPwd = elemValidation.Element("EncPwd").Value;
sKey1 = elemValidation.Element("Key1").Value;
sKey2 = elemValidation.Element("Key2").Value;
}
byte[] Key1 = encoding.GetBytes(sKey1);
byte[] Key2 = encoding.GetBytes(sKey2);
byte[] Data = encoding.GetBytes(sPwd);
// Decrypt the buffer back to a string.
string Final = DecryptTextFromMemory(Data, Key1, Key2);
return Final;
此数据是实际数据输出..
- <EmailPwd>
- <EncPwd>
- <![CDATA[ ?????@]Z
]]>
</EncPwd>
- <Key1>
- <![CDATA[ ~??s????E&?3??2?3I?????
]]>
</Key1>
- <Key2>
- <![CDATA[ ???h?6
]]>
</Key2>
</EmailPwd>
答案 0 :(得分:1)
您的数据中似乎有一个字符0x08。根据{{3}},这不是有效的XML,因此解析器在引发错误时是正确的
您必须将数据更改为有效的XML - 通过更改无效字符。 和/或要求数据供应商提供他们目前没有做的XML。