diff options
Diffstat (limited to 'src/uscxml/DOMUtils.cpp')
-rw-r--r-- | src/uscxml/DOMUtils.cpp | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/uscxml/DOMUtils.cpp b/src/uscxml/DOMUtils.cpp index afb806b..e54099e 100644 --- a/src/uscxml/DOMUtils.cpp +++ b/src/uscxml/DOMUtils.cpp @@ -26,41 +26,41 @@ namespace uscxml { std::string DOMUtils::xPathForNode(const Arabica::DOM::Node<std::string>& node) { - std::string xPath; - + std::string xPath; + if (!node || node.getNodeType() != Arabica::DOM::Node_base::ELEMENT_NODE) return xPath; - - Arabica::DOM::Node<std::string> curr = node; + + Arabica::DOM::Node<std::string> curr = node; while(curr) { switch (curr.getNodeType()) { - case Arabica::DOM::Node_base::ELEMENT_NODE: { - if (HAS_ATTR(curr, "id")) { - // we assume ids to be unique and return immediately - xPath.insert(0, "//" + TAGNAME(curr) + "[@id=\"" + ATTR(curr, "id") + "\"]"); - return xPath; - } else { - // check previous siblings to count our index - Arabica::DOM::Node<std::string> sibling = curr.getPreviousSibling(); - int index = 1; - while(sibling) { - if (sibling.getNodeType() == Arabica::DOM::Node_base::ELEMENT_NODE) { - if (iequals(TAGNAME(sibling), TAGNAME(curr))) { - index++; - } + case Arabica::DOM::Node_base::ELEMENT_NODE: { + if (HAS_ATTR(curr, "id")) { + // we assume ids to be unique and return immediately + xPath.insert(0, "//" + TAGNAME(curr) + "[@id=\"" + ATTR(curr, "id") + "\"]"); + return xPath; + } else { + // check previous siblings to count our index + Arabica::DOM::Node<std::string> sibling = curr.getPreviousSibling(); + int index = 1; + while(sibling) { + if (sibling.getNodeType() == Arabica::DOM::Node_base::ELEMENT_NODE) { + if (iequals(TAGNAME(sibling), TAGNAME(curr))) { + index++; } - sibling = sibling.getPreviousSibling(); } - xPath.insert(0, "/" + TAGNAME(curr) + "[" + toStr(index) + "]"); + sibling = sibling.getPreviousSibling(); } - break; + xPath.insert(0, "/" + TAGNAME(curr) + "[" + toStr(index) + "]"); } - case Arabica::DOM::Node_base::DOCUMENT_NODE: - return xPath; - default: - LOG(ERROR) << "Only nodes of type element supported for now"; - return ""; - break; + break; + } + case Arabica::DOM::Node_base::DOCUMENT_NODE: + return xPath; + default: + LOG(ERROR) << "Only nodes of type element supported for now"; + return ""; + break; } curr = curr.getParentNode(); } |