由于您已经拥有<代码>逐[]代码>阵列,因此,在阵列之前和之后,在记忆流上,应更方便地撰写:
// bytes from db
byte[] multipleNodes = Encoding.UTF8.GetBytes("<first>..</first><second>..</second><third>..</third>");
using (var ms = new MemoryStream())
{
// write opening tag
byte[] newRoot = Encoding.UTF8.GetBytes("<newRoot>");
ms.Write(newRoot, 0, newRoot.Length);
ms.Write(multipleNodes, 0, multipleNodes.Length);
// write opening tag
byte[] closeNewRoot = Encoding.UTF8.GetBytes("</newRoot>");
ms.Write(closeNewRoot, 0, closeNewRoot.Length);
// reset cursor position before pass it to xmldoc
ms.Position = 0;
var xml = new XmlDocument();
xml.Load(ms);
Console.WriteLine(xml.InnerXml);
}
但是,由于<代码>XmlDocument也提供了<编码>LoadXml(str),我觉得操纵扼杀应当更直接地解决问题:
// bytes from db
byte[] multipleNodes = Encoding.UTF8.GetBytes("<first>..</first><second>..</second><third>..</third>");
string stringFromBlob = Encoding.UTF8.GetString(multipleNodes);
string withRootNode = string.Format("<newRoot>{0}</newRoot>", stringFromBlob);
var xml = new XmlDocument();
xml.LoadXml(withRootNode);
Console.WriteLine(xml.InnerXml);