I am trying to write a Linq query which will parse my XML tree(which is actually a SQL deconstructed into an XML tree).
My XML looks like this
<SqlRoot>
<SqlStatement>
<Clause>
<OtherKeyword>select</OtherKeyword>
<WhiteSpace></WhiteSpace>
<Other>t1</Other>
<Period>.</Period>
<Other>empid</Other>
<WhiteSpace></WhiteSpace>
</Clause>
<Clause>
<OtherKeyword>from</OtherKeyword>
<SelectionTarget>
<WhiteSpace></WhiteSpace>
<Other>bd_orm</Other>
<Period>.</Period>
<Other>dbo</Other>
<Period>.</Period>
<Other>bal_impacts_t</Other>
<WhiteSpace></WhiteSpace>
<Other>t1</Other>
</SelectionTarget>
</Clause>
</SqlStatement>
</SqlRoot>
I am trying to pick out the table name (SelectionTarget
node). The WhiteSpace
node is a blank/white space in between the values.
So the output which I expect is something like this bd_orm.dbo.bal_impacts_t t1
but I am unable to figure out how to do this by including a whitespace
in between.
I tried this
var xxx = (from res in xDoc.Descendants("Clause").Descendants("SelectionTarget") select res);
Console.WriteLine(xxx.DescendantNodesAndSelf().OfType<XElement>().First().Value);
but it obviously fail cause I do not know how to take into account the whitespace
node and convert that into an actual whitespace
. Any suggestions?
Simply select a space for the
WhiteSpace
nodes and the string value for all other nodes, then concatenate the results: