我试图将现有的XML文件“嵌入”到另一个“根”XML文件的另一个节点中。假设有一个通往现有xml文件的路径.
StreamReader reader = new StreamReader(path);
string lines = reader.ReadLine();
while (!reader.EndOfStream)
{
lines = reader.ReadLine();
}
XDocument doc = new XDocument(
new XComment("You can copy and paste or open the XML in Excel."),
new XElement("Root",
new XElement("logs",lines))
);我的结局是这样的:
<Root><logs><log><username>otonomy</
一些解码程序需要帮助。
发布于 2013-10-18 20:02:27
使用XElement.Load()静态方法代替:
XDocument doc = new XDocument(
new XComment("You can copy and paste or open the XML in Excel."),
new XElement("Root",
new XElement("logs"
XElement.Load(path)))
);它可以直接使用path,因此您根本不必处理StreamReader。
发布于 2013-10-18 20:02:44
尝试:
string lines = File.ReadAllText( path );
XDocument doc = new XDocument(
new XComment( "You can copy and paste or open the XML in Excel." ),
new XElement( "Root",
new XElement( "logs", XElement.Parse( lines ) ) ) );https://stackoverflow.com/questions/19458012
复制相似问题