How to select multiple nodes in different levels?

那年仲夏 提交于 2019-12-04 22:56:18

You can use a union in your XPath expression. Just use the operator: |

//Document/Placemark/name | //Document/Placemark/Polygon/coordinates

Don't use the // (descendant axis) if you don't need to. Using //, this would also work: //name | //coordinates. It's better performance-wise to specify the exact path.

Use:

/*/*/Placemark/name | /*/*/Placemark/*/coordinates

This specifies the union of the results of two separate XPath expressions -- the standard XPath union operator | is used. Selected are all name elements that are children of a Placemark element that is a grandchild of the top element of the XML document, plus all coordinates elements that are grand-children of a Placemark element that is a grandchild of the top element of the XML document.

The selected elements come in document order (although no normative W3C document specifies the order), which means that in the result of the evaluation (usually of type XmlNodeList) any name element is directly followed by its corresponding coordinates element.

Resolved: //Placemark/*[self::name or descendant::coordinates]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!