0

子ノードを基準に XML ファイルを分割し、分割したファイルを表示したい。

4

1 に答える 1

0

完全な情報は提供されていませんが、要件に近いサンプル コードを次に示します。

ChildNode という名前の多くの子ノードを含む main.xml ファイルを読み取り、子ノードごとに個別のファイルを書き込みます。

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++;
}

xml ドキュメントをチャンクに分割する で同様の回答を確認することもできます

于 2012-05-02T07:40:20.290 に答える