【问题标题】:Filter child elements, but keep the original structure with XPath过滤子元素,但使用 XPath 保留原始结构
【发布时间】:2012-10-15 21:03:01
【问题描述】:

我怎么能从中得到:

<a id="1">
    <b>
        <c type="1"/>
        <c type="0"/>
        <c type="0"/>
    </b>
    <b>
        <c type="1"/>
        <c type="0"/>
        <c type="1"/>
    </b>
</a>
<a id="2">
    <b>
        <c type="1"/>
        <c type="1"/>
        <c type="0"/>
    </b>
    <b>
        <c type="1"/>
        <c type="1"/>
    </b>
</a>

以下内容:

<a id="1">
    <b>
        <c type="1"/>
    </b>
    <b>
        <c type="1"/>
        <c type="1"/>
    </b>
</a>
<a id="2">
    <b>
        <c type="1"/>
        <c type="1"/>
    </b>
    <b>
        <c type="1"/>
        <c type="1"/>
    </b>
</a>

所以我想过滤元素,但保留原始结构。我使用 sql 服务器。 我尝试了一些变化,但都没有像我预期的那样工作。

【问题讨论】:

  • 到底是什么问题?你尝试过什么,你在哪里卡住了?

标签: sql-server xml xpath filter xquery


【解决方案1】:

@x 是你的 xml...

set  @x.modify('delete (/a/b/c[@type="0"])')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 2017-07-22
    • 2023-02-24
    • 2012-09-21
    相关资源
    最近更新 更多