I have got an XML node called ‘structNumber’ which has data similar to ‘4.2’
I select the node using:
XmlNode xnChapNr = xDoc.SelectSingleNode("//./structNumber");
And at present I am displaying it by:
string chapNr = (xnChapNr == null) ? "X" : xnChapNr.InnerText
This then displays the entire string ‘4.2’.
What I need however, is a way to only select the ‘4’ for this string and the ‘2’ for another.
Is there an extension for InnerText? I have read through the documentation but nothing appears to work as I wish it to.
If it is helpful to know; what this code does in its entirety is produce a tree structure of an XML document. I.e:
Chapter 4,
Section 4.1,
Sub section 4.1.1,
Section 4.2,
ect…
Any and all help will be much appreciated.
string chapNr = (xnChapNr == null) ? "X" : xnChapNr.InnerText.ToString().Split(new char[]{'.'})[0]will return you 4 andstring chapNr = (xnChapNr == null) ? "X" : xnChapNr.InnerText.ToString().Split(new char[]{'.'})[1]will return you 2