[英]inclusion of xml file in c#
this is my question, i have two xml files and i want to include child file in father files to see as one like following 这是我的问题,我有两个xml文件,我想在父文件中包含子文件,如下所示
<?xml version="1.0" encoding="UTF-8"?>
<topolino.doc name="topolino.doc" type="doc" path="C:\Users\" filename="topolino.doc">
<child.xml type="xml" name="child.xml" path="C:\" filename="child.xml" />
</topolino.doc>
<?xml version="1.0" encoding="UTF-8"?>
<adeel.doc name="adeel.doc" type="doc" path="C:" filename="adeel.doc">
<pippo.doc type="doc" name="pippo.doc" path="C:" filename="pippo.doc" />
</adeel.doc>
<?xml version="1.0" encoding="UTF-8"?>
<topolino.doc name="topolino.doc" type="doc" path="C:\Users\" filename="topolino.doc">
<adeel.doc name="adeel.doc" type="doc" path="C:" filename="adeel.doc">
<pippo.doc type="doc" name="pippo.doc" path="C:" filename="pippo.doc" />
</adeel.doc>
</topolino.doc>
what is the best way to do it? 最好的方法是什么?
thx in advance Andy 提前谢谢安迪
string strParent=@"<?xml version=""1.0"" encoding=""UTF-8""?>
<topolino.doc name=""topolino.doc"" type=""doc"" path=""C:\Users\"" filename=""topolino.doc""> \
<child.xml type=""xml"" name=""child.xml"" path=""C:\"" filename=""child.xml"" />
</topolino.doc>";
string strChild = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<adeel.doc name=""adeel.doc"" type=""doc"" path=""C:"" filename=""adeel.doc"">
<pippo.doc type=""doc"" name=""pippo.doc"" path=""C:"" filename=""pippo.doc"" />
</adeel.doc>";
XmlDocument docParent = new XmlDocument();
docParent.LoadXml(strParent);
XmlDocument docChild = new XmlDocument();
docChild.LoadXml(strChild);
//docParent.AppendChild(docChild.ChildNodes.Item(0));
var n = docParent.ImportNode(docChild.SelectSingleNode("adeel.doc"), false);
var n1 = docParent.ImportNode(docChild.ChildNodes[1].SelectSingleNode("pippo.doc"), true);
docParent.DocumentElement.AppendChild(n);
docParent.DocumentElement.AppendChild(n1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.