How do I check for any unbalanced set of parentheses inside a node using LINQ-to-XML, for example
="1.0"
<root>
<child1>Anything goes <a>(here</a>) and <bb>(there)</bb>!</child1>
<child2>Whatever <a>goes (around)</a> <bb>comes around()</bb> and (<a>that is)</a> a fact.</child1>
</root>
In the above sample xml, the node
<a>(here</a>
contains only a opening parentheses inside the node and the closing parentheses is outside the node, in that case I want to re-position that opening parentheses to just before the
<a>
node as
(<a>here</a>)
and the same logic for any node like
(<a>that is)</a>
should be replaced as
(<a>that is</a>)
and
<a>goes (around)</a>
should remain unchanged as it contains a complete set of opening and closing parentheses, however
<bb>(there)</bb>
should also be changed to
(<bb>there</bb>)
as both the opening and closing parentheses are positioned immediately after and before the nodes.
Can anybody help!!
What I have tried:
I'm clueless how to do this to be honest
XDocument xml = XDocument.Load(@"D:\test.xml");
var targetnodes=from x in xml.Descendants("a")
where ????
Also, here are some other types for better understanding
<bb>(statistical moments of the 1(st) - 4(th) (order))</bb>
(<bb>statistical moments of the 1(st) - 4(th) (order))</bb>
<bb>(statistical moments of the 1(st) - 4(th) (order)</bb>)
<bb>((statistical moments) of the 1(st) - 4(th) (order)</bb>)
should be
(<bb>statistical moments of the 1(st) - 4(th) (order)</bb>)
(<bb>statistical moments of the 1(st) - 4(th) (order)</bb>)
(<bb>statistical moments of the 1(st) - 4(th) (order)</bb>)
(<bb>(statistical moments) of the 1(st) - 4(th) (order)</bb>)