xpath: select parent and filtered children

后端 未结 1 1066
小蘑菇
小蘑菇 2021-01-20 07:09

Given an xml block of:


    
    

How might I use xpath to re

相关标签:
1条回答
  • 2021-01-20 08:03

    With just XPath, you can't.

    XPath allows you to query (select) nodes from an XML document tree, but it can't modify a tree or create new nodes. So if you select the original <parent> node, it will have two <child> children, and you can't change that. In order to get a <parent> with only one child, you'd have to either modify the original <parent> to delete its other child, or create a new <parent>.

    You could do this with XSLT, as you alluded to; or a number of other XML tree-building technologies. If you tell us what kind of platform you're building on, we could suggest ones that are most relevant to your platform.

    0 讨论(0)
提交回复
热议问题