I have an XML file as follows
<?xml version="1.0>
<EMR>
<CustomTextBox>
<Text>WNL</Text>
<Type>TextBox</Type>
<Width>500</Width>
<id>txt1</id>
</CustomTextBox>
<CustomTextBox>
<Text>WNL</Text>
<Type>TextBox</Type>
<Width>500</Width>
<id>txt2</id>
</CustomTextBox>
<AllControlsCount>
<Width>0</Width>
<id>ControlsID</id>
</AllControlsCount>
</EMR>
I want to split the xml file int o three. According to its nodes
File 1:
<?xml version="1.0>
<CustomTextBox>
<Text>WNL</Text>
<Type>TextBox</Type>
<Width>500</Width>
<id>txt1</id>
</CustomTextBox>
File 2:
<?xml version="1.0>
<CustomTextBox>
<Text>WNL</Text>
<Type>TextBox</Type>
<Width>500</Width>
<id>txt2</id>
</CustomTextBox>
File 3:
<?xml version="1.0>
<AllControlsCount>
<Width>0</Width>
<id>ControlsID</id>
</AllControlsCount>
Also the nodes are dynamic, they may change. How can I split this xml file as multiple according to the nodes. If anybody knows please share.
Try LinqToXml:
It will take all elements defined inside the root element and write its content into separate files.