在asp.net中基于子节点值拆分XML文件

在asp.net中基于子节点值拆分XML文件,asp.net,xml,dom,Asp.net,Xml,Dom,我想基于子节点拆分XML文件,并显示拆分后的文件。虽然您没有提供完整信息,但下面是接近您要求的示例代码 它读取main.xml文件,该文件包含许多名为ChildNode的子节点,并为每个子节点编写单独的文件 XmlDocument xml= new XmlDocument(); xml.Load(@"c:\main.xml"); XmlNodeList xnRep = xml.DocumentElement.GetElementsByTagName("ChildNode"); string

我想基于子节点拆分XML文件,并显示拆分后的文件。

虽然您没有提供完整信息,但下面是接近您要求的示例代码

它读取main.xml文件,该文件包含许多名为ChildNode的子节点,并为每个子节点编写单独的文件

XmlDocument xml= new XmlDocument();
xml.Load(@"c:\main.xml");

XmlNodeList xnRep = xml.DocumentElement.GetElementsByTagName("ChildNode");

string strFileName = "ChildNode";
int intFileCount;

for(int i =0; i <xnRep.Count;i++)
{
          //Stores the ChildNode Elements in the Variable
          strDest = xnRep[i].InnerXml;

          //Create the New File with the name "ChildNode_1.xml" and "ChildNode_3.xml" 
          XmlWriter xw = XmlWriter.Create(strFileName + "_" + intFileCount + ".xml");

          //Write the XML
          xw.WriteRaw(strDest.ToString());

          xw.Close();

          intFileCount++;
}
xmldocumentxml=newxmldocument();
Load(@“c:\main.xml”);
XmlNodeList xnRep=xml.DocumentElement.GetElementsByTagName(“ChildNode”);
字符串strFileName=“ChildNode”;
int文件计数;

对于(int i=0;我可以显示您尝试过的内容吗?示例xml?显示分割文件是什么意思?