从此 XML 标记中提取选定节点值的方法
鉴于下面列出的(样本 - 真实标记可能要复杂得多)标记和约束,任何人都可以提出一个比遍历整个树来检索 { "@@value1@@", "@@ 更有效/高效的解决方案 (C#) value2@@", "@@value3@@" },即实际使用标记时将被替换的标记列表。
注意:我无法控制标记、标记结构或要替换的标记的格式/命名。
<markup>
<element1 attributea="blah">@@value1@@</element1>
<element2>@@value2@@</element2>
<element3>
<element3point1>@@value1@@</element3point1>
<element3point2>@@value3@@</element3point2>
<element3point3>apple</element3point3>
<element3>
<element4>pear</element4>
</markup>
Given the (specimen - real markup may be considerably more complicated) markup and constraints listed below, could anyone propose a solution (C#) more effective/efficient than walking the whole tree to retrieve { "@@value1@@", "@@value2@@", "@@value3@@" }, i.e. a list of tokens that are going to be replaced when the markup is actually used.
Note: I have no control over the markup, structure of the markup or format/naming of the tokens that are being replaced.
<markup>
<element1 attributea="blah">@@value1@@</element1>
<element2>@@value2@@</element2>
<element3>
<element3point1>@@value1@@</element3point1>
<element3point2>@@value3@@</element3point2>
<element3point3>apple</element3point3>
<element3>
<element4>pear</element4>
</markup>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样:
这:
MatchCollection
想要)但是,它可能会构建一个更大的字符串,所以可能只是
匹配
:How about:
This:
MatchCollection
with the duplicates we don't want)However, it may build a larger string, so maybe just
Matches
:我用你的示例编写了一个快速程序,这应该可以解决问题。
I wrote a quick prog with your sample, this should do the trick.