I have the following XML file:
<root>
<table>
<items>Item 1</items>
</table>
<table>
<items>Item 2</items>
</table>
<table>
<items>Item 3</items>
</table>
<table>
<items>Item 4</items>
</table>
<table>
<items>Item 5</items>
</table>
<table>
<items>Item 6</items>
</table>
<table>
<items>Item 7</items>
</table>
<table>
<items>Item 8</items>
</table>
</root>
I want to merge all items values into one node so I can use that nodes value in some piece of code. Every 2 values it should be separated with a "/".
I managed to write some code and my result right now is this:
<root>
<table>
<items>Item 1, Item 2, Item 3, Item 4, Item 5, Item 6, Item 7, Item 8</items>
</table>
</root>
However the end result should look like this:
<root>
<table>
<items>Item 1, Item 2 / Item 3, Item 4 / Item 5, Item 6 / Item 7, Item 8</items>
</table>
</root>
EDIT: This is the code I used for getting what I have right now:
var input = "XML";
XDocument doc = XDocument.Parse(input);
XElement root = doc.Root;
XElement parentTable = root.Element("parentTable");
parentTable.Add(new XElement("components"));
XElement components = parentTable.Element("components");
ArrayList componentArray = new ArrayList();
foreach (var d in doc.Descendants("table"))
{
componentArray.Add(d.Value + ", ");
}
components.Add(componentArray);
doc.Save("XML");