我们有C#代码,它通过ManagementObjectsearcher获取一些系统信息并将其编码为XmlDocument。它看起来像这样:
searcher = new ManagementObjectSearcher(managementScope, new ObjectQuery("SELECT * FROM Win32_ComputerSystem"));
foreach (ManagementObject obj in searcher.Get())
{
if (obj["Manufacturer"] != null)
{
temp = obj["Manufacturer"].ToString();
if (temp.Length > 0)
{
node = doc.CreateElement("Manufacturer");
node.InnerText = Regex.Replace(temp, "[ ]+", " ").Trim();
nodeDesc.AppendChild(node);
if (obj["Model"] != null)
{
temp = obj["Model"].ToString();
if (temp.Length > 0)
{
node = doc.CreateElement("Model");
node.InnerText = Regex.Replace(temp, "[ ]+", " ").Trim(); ;
nodeDesc.AppendChild(node);
}
}
在非常罕见的情况下,在调用doc.OuterXml时,会抛出异常:
"The surrogate pair (0xD8AC, 0xE332) is invalid. A high surrogate character (0xD800 - 0xDBFF) must always be paired with a low surrogate characters (0xDC00-0xDFFF)."
我怀疑这种情况发生在XP机器上,其中编码以某种方式设置不同,例如中文Windows XP。也许obj [“xxxxx”]返回一个用Big5或GB编码的字符串。
非常感谢你的帮助!这个特别让我很生气,因为我们还没有办法在内部复制它。