如何查找特定节点的子元素?与TinyXpath [英] How to find child elements of a specific node ? with TinyXpath

查看:295
本文介绍了如何查找特定节点的子元素?与TinyXpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功将TinyXpath与以下根节点一起使用

I have successfully used TinyXpath with root node as below

const char* xpath ="/MyRoot/A/B";
TinyXpath::xpath_processor xp_proc(mRootElement, xpath);

(这将在MyRoot的所有A下找到所有B)

(this will find all B under all A of MyRoot)

我想知道是否可以将非根元素传递给构造函数,如下所示

I wonder if I can pass non-root element to the constructor something like below

const char* xpath = "./A/B";
TinyXpath::xpath_processor xp_proc(A_Element, xpath);

(当我有A_Element时,我想在特定A下找到所有B)

谢谢

推荐答案

从TinyXPath文档中获得以下构造函数定义:

xpath_processor (const TiXmlNode *XNp_source_tree, 
                 const char *cp_xpath_expr)

您可以:

xpath_processor(A_Element, "A/B");

假定A_Element的类型为TiXmlNode*

这将选择所有B元素,这些元素是A元素的子元素,而A元素是A_Element引用的元素的子元素.

This will select all B elements that are children of an A element that is a child of the element referenced by A_Element.

如果要选择作为A_Element所引用元素的子元素的所有B元素,则调用应为:

In case you want to select all B elements that are children of the element referenced by A_Element, then the call should be:

xpath_processor(A_Element, "B");

这篇关于如何查找特定节点的子元素?与TinyXpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆