I have a number of XPaths from which I'd like to create an XML document, probably using the XmlDocument
class and preferably utilising some existing functionality rather than building node-by-node in some kind of possibly recursive loop.
So given the 3 xpaths:
THIS/IS/FIRST/XPATH
THIS/IS/FIRST/XPATH/GOING/DEEPER
THIS/IS/SECOND/XPATH
I would like to produce:
<THIS>
<IS>
<FIRST>
<XPATH>
<GOING>
<DEEPER>
</DEEPER>
</GOING>
</XPATH>
</FIRST>
<SECOND>
<XPATH>
</XPATH>
</SECOND>
</IS>
</THIS>
I'm hoping the code is something simply along the lines of this, with XPaths being added in any order:
var doc = new XmlDocument();
doc.AddXPath("THIS/IS/FIRST/XPATH");
doc.AddXPath("THIS/IS/SECOND/XPATH");
doc.AddXPath("THIS/IS/FIRST/XPATH/GOING/DEEPER");
string result = doc.ToString();`
Many thanks!