You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何筛选XML中符合特定属性与子元素条件的<children>元素

XML元素筛选解决方案

原始XML内容

<children xmi:type="notation:General" xmi:id="1">
  <children xmi:type="notation:Shape" xmi:id="2">
    <element xmi:type="uml:Package" href="krZQ"/>
  </children>
  <children xmi:type="notation:Shape" xmi:id="3">
    <element xmi:type="uml:Package" href="wtFm"/>
  </children>
  <children xmi:type="notation:Shape" xmi:id="4"/>
</children>

需求1:筛选带指定属性且包含<element>子元素的<children>

用XPath表达式就能精准匹配:

//children[@xmi:type='notation:Shape' and element]

匹配结果:

<children xmi:type="notation:Shape" xmi:id="2">
  <element xmi:type="uml:Package" href="krZQ"/>   
</children>
<children xmi:type="notation:Shape" xmi:id="3">
  <element xmi:type="uml:Package" href="wtFm"/>   
</children>

需求2:根据<element>的href属性筛选特定<children>

如果要匹配指定href值(比如href="wtFm"),用以下XPath表达式:

//children[@xmi:type='notation:Shape' and element/@href='wtFm']

匹配结果:

<children xmi:type="notation:Shape" xmi:id="3">
  <element xmi:type="uml:Package" href="wtFm"/>   
</children>

内容的提问来源于stack exchange,提问作者KeepGoing

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 08:30:17