我正在尝试从我正在连接的服务器读取 XML。不幸的是,我没有办法最终纠正这个问题。我遇到了一个例外:
Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 1, position 3.
我相信这是因为他们以数据开头,<? LLSD/XML ?>
并且鉴于第三个字符是 a
它会引发此异常。我的问题是,我该如何解决这个问题?其余数据是有效的 XML。我已经能够使用 expat、tinyxml 等在 C++ 中成功解析它,但是 System.Xml.XmlReader 失败了。目前,我正在这样做:
public static OSD DeserializeLLSDXml(Stream xmlStream)
{
XmlReaderSettings settings = new XmlReaderSettings
{
ValidationType = ValidationType.None,
CheckCharacters = false,
IgnoreComments = true,
IgnoreProcessingInstructions = true,
DtdProcessing = DtdProcessing.Prohibit
};
using (XmlReader xrd = XmlReader.Create(xmlStream))
{
return DeserializeLLSDXml(xrd);
}
}
public static OSD DeserializeLLSDXml(XmlReader xmlData)
{
try
{
xmlData.Read();
SkipWhitespace(xmlData);
xmlData.Read();
OSD ret = ParseLLSDXmlElement(xmlData);
return ret;
}
catch (XmlException ex)
{
string exs = ex.ToString();
return new OSD();
}
}
我收到的示例消息:
<? LLSD/XML ?>\n
<llsd>
<map>
<key>MINUTES</key>
<integer>5</integer>
<key>NAME</key>
<string>Hippotropolis</string>
</map>
</llsd>\n