【问题标题】:Select XML from list of XML only if the Child elements tags values are matched仅当子元素标记值匹配时,才从 XML 列表中选择 XML
【发布时间】: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


【解决方案1】:

在 Notepad++ 中添加 XML Tools 插件,评估以下 xpath 表达式并查看它是否有效:

//ns:Input[//ns:name[text()='def']][ns:locationevent[text()='yyyy']][ns:ID[text()='1423']]

【讨论】:

  • 尝试用&lt;?xml version="1.0"?&gt; &lt;doc xmlns:ns="http://www.example"&gt;在顶部和&lt;/doc&gt;包装你的xml,看看这是否适合你。
  • 它没有用。你能在截图中放置并解释一下吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-07
  • 2016-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
  • 2011-04-20
相关资源
最近更新 更多