本文介绍了如何检查节点内不平衡的括号集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用LINQ-to-XML检查节点内任何不平衡的括号集,例如

How do I check for any unbalanced set of parentheses inside a node using LINQ-to-XML, for example

<?xml version="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>



在上面的示例xml中,节点< a>(此处< / a> 在节点内只包含一个左括号,而右括号在节点外,在这种情况下,我想将那个开括号重新定位在< a> 节点为(< a> here< / a>)和任何节点的逻辑相同,如(< a>)< ; / a> 应替换为(< a>即< / a>)并且< a> go(around)< / a> 应该保持不变,因为它包含一组完整的开括号和右括号,但< bb>(那里)< / bb> 也应更改为(< bb>那里< / bb>)作为开场并且关闭括号位于节点之后和之前。

任何人都可以提供帮助!!



我尝试了什么:



说实话,我真的很无能为力


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 ????



此外,这里有一些其他类型可以更好地理解

< bb>(统计时刻) 1(st) - 4(th)(订单))< / bb>

(< bb>统计时刻的1(st) - 4(th)(order))< / bb>

< bb>(统计时刻1( st) - 4(th)(订单)< / bb>)

< bb>((统计时刻)1( st) - 4(th)(订单)< / bb>)

应该是

(< bb> 1(st)-4(th)的统计时刻(顺序)< / bb>)

(< bb>统计时刻1(st) - 4(th)(顺序)< / bb>)

(< bb>统计时刻1(st) - 4(th)(订单)< / bb>)

(< bb>(统计时刻) 1(st) - 4(th)(订单)< / bb>)

推荐答案


这篇关于如何检查节点内不平衡的括号集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 00:45