/**
* @brief Gets a XPath from specific id.
*
- * @param id
+ * @param node AccessibleNode
*
* @return XPath
*
* @since_tizen 7.0
*/
- std::string getXPath(std::string id);
+ std::string getXPath(std::shared_ptr<AccessibleNode> node);
/**
* @brief Finds that objects that satisfied with the xpath in the object tree.
*
* @brief Check xml_node exists or not
*
- * @param string id
+ * @param node AccessibleNode
*
* @return xml_node
*
* @since_tizen 7.0
*/
- xml_node checkNode(std::string id);
+ xml_node checkNode(std::shared_ptr<AccessibleNode> node);
+
+ /**
+ * @internal
+ *
+ * @brief Check parent's xml_node exists or not
+ *
+ * @param node AccessibleNode
+ *
+ * @return AccessibleNode
+ *
+ * @since_tizen 7.5
+ */
+ std::shared_ptr<AccessibleNode> checkParentNode(std::shared_ptr<AccessibleNode> node);
private:
xml_document *mDoc;
return query;
}
-xml_node AurumXML::checkNode(std::string id)
+std::shared_ptr<AccessibleNode> AurumXML::checkParentNode(std::shared_ptr<AccessibleNode> node)
{
- xml_node node;
+ auto parent = node->getParent();
+ if (!parent) return nullptr;
+
+ std::string query = makeQuery(node->getId());
+ xml_node xmlNode = mDoc->select_node(query.c_str()).node();
+
+ if (xmlNode) {
+ int childCnt = parent->getChildCount();
+ for (int i = 0; i < childCnt; i++) {
+ std::shared_ptr<AccessibleNode> childNode = parent->getChildAt(i);
+ if (childNode->getRawHandler() == nullptr) continue;
+
+ xml_node childElement = xmlNode.append_child("");
+ traverse(childElement, childNode);
+ }
+ return parent;
+ }
+
+ return checkParentNode(parent);
+}
+
+xml_node AurumXML::checkNode(std::shared_ptr<AccessibleNode> node)
+{
+ xml_node xmlNode;
+
try {
- std::string query = makeQuery(id);
- node = mDoc->select_node(query.c_str()).node();
+ std::string query = makeQuery(node->getId());
+ xmlNode = mDoc->select_node(query.c_str()).node();
+
+ if (!xmlNode) {
+ // 1. find parent and check node again
+ auto parent = checkParentNode(node);
+
+ // 2. clear tree and create tree again
+ if (!parent) createXMLtree();
- if (!node) {
- createXMLtree();
- node = mDoc->select_node(query.c_str()).node();
+ xmlNode = mDoc->select_node(query.c_str()).node();
}
} catch (const xpath_exception &e) {
LOGI("getXPath Error: %s", e.what());
}
- return node;
+ return xmlNode;
}
-std::string AurumXML::getXPath(std::string id)
+std::string AurumXML::getXPath(std::shared_ptr<AccessibleNode> node)
{
- xml_node node = checkNode(id);
+ xml_node xmlNode = checkNode(node);
- if (node) {
- std::string xpath = getOptimalXPath(mDoc, node);
+ if (xmlNode) {
+ std::string xpath = getOptimalXPath(mDoc, xmlNode);
return xpath;
}