How to find child elements of a specific node ? with TinyXpath

走远了吗. 提交于 2020-01-25 02:12:34

问题


I have successfully used TinyXpath with root node as below

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

(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);

(I want to find all B under specific A, when I have A_Element)

Thank you


回答1:


Given this constructor definition from the TinyXPath documentation:

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

You could have:

xpath_processor(A_Element, "A/B");

provided that A_Element is of type TiXmlNode*

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

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");


来源:https://stackoverflow.com/questions/5617271/how-to-find-child-elements-of-a-specific-node-with-tinyxpath

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