【发布时间】:2020-01-04 19:08:44
【问题描述】:
对于给定的 Xml 列表
<ns:Input>
<ns:location>asfsafs</ns:location>
<ns:locationevent>xxxx</ns:locationevent>
<ns:Action>
<ns:name>abc</ns:name>
</ns:Action>
<ns:Action>
<ns:name>ghy</ns:name>
</ns:Action>
<ns:Coverage>
<ns:Action>
<ns:name>deg</ns:name>
</ns:Action>>
</ns:Coverage>
<ns:ID>12133</ns:ID>
</ns:Input>
<ns:Input>
<ns:location>asfsafs</ns:location>
<ns:locationevent>yyyy</ns:locationevent>
<ns:Action>
<ns:name>abc</ns:name>
</ns:Action>
<ns:Action>
<ns:name>def</ns:name>
</ns:Action>
<ns:Coverage>
<ns:Action>
<ns:name>def</ns:name>
</ns:Action>
</ns:Coverage>
<ns:ID>12233</ns:ID>
</ns:Input>
<ns:Input>
<ns:location>asfsafs</ns:location>
<ns:locationevent>yyyy</ns:locationevent>
<ns:Action>
<ns:name>abc</ns:name>
</ns:Action>
<ns:Action>
<ns:name>def</ns:name>
</ns:Action>
<ns:Coverage>
<ns:Action>
<ns:name>def</ns:name>
</ns:Action>
</ns:Coverage>
<ns:ID>1423</ns:ID>
</ns:Input>
<ns:Input>
<ns:location>asfsafs</ns:location>
<ns:locationevent>xxxx</ns:locationevent>
<ns:Action>
<ns:name>abc</ns:name>
</ns:Action>
<ns:Action>
<ns:name>ghy</ns:name>
</ns:Action>
<ns:Coverage>
<ns:Action>
<ns:name>deg</ns:name>
</ns:Action>>
</ns:Coverage>
<ns:ID>12</ns:ID>
</ns:Input>
我只想选择符合以下条件的 XML 在此输入代码
<ns:Input>..<ns:locationevent>yyyy</ns:locationevent>..<ns:Action>..<ns:name>def</ns:name>..
<ns:Input>..<ns:Coverage>..<ns:Action>..<ns:name>def</ns:name>..<ns:ID>1423</ns:ID>..</ns:Input>
如果在记事本++中使用以下命令,
<ns:Input>(?:(?!</ns:Input>).)*<ns:locationevent>yyyy</ns:locationevent.*?<ns:Action>.*?
<ns:name>def</ns:name>.*?<ns:Coverage>.*?<ns:Action>.*?<ns:name>def</ns:name>(?:(?!</ns:Input>).)*
(1423).*?</ns:Input>
它会选择第二个和第三个 XMls。它应该只选择符合上述条件的第三个 XML。
你能帮忙吗?这应该在 Notepad++ 正则表达式中完成。
【问题讨论】:
-
这不是正则表达式的工作;你应该尝试像xpath这样的东西。另外,你想要的输出到底是什么?
-
我在帖子中提到,如果我使用上述命令,我只需要 XML 列表中的 3td XML。
-
我不知道“XML 列表中的 3td XML”是什么;请编辑您的问题并准确地发布所需输出的样子。
-
我需要下面的 XML 作为输出 符合以下条件的。跨度>
标签: xml xml-parsing notepad++ extract parent