public boolean xpathEnsure(String xpath) throws ParseException {
    try {

      //Quick exit for common case
      if (xpathSelectElement(xpath) != null) return false;

      //Split XPath into dirst step and bit relative to rootElement
      final XPath parseTree = XPath.get(xpath);
      int stepCount = 0;
      for (Enumeration i = parseTree.getSteps(); i.hasMoreElements();) {
        i.nextElement();
        ++stepCount;
      }
      Enumeration i = parseTree.getSteps();
      Step firstStep = (Step) i.nextElement();
      Step[] rootElemSteps = new Step[stepCount - 1];
      for (int j = 0; j < rootElemSteps.length; ++j)
        rootElemSteps[j] = (Step) i.nextElement();

      //Create root element if necessary
      if (rootElement_ == null) {
        Element newRoot = makeMatching(null, firstStep, xpath);
        setDocumentElement(newRoot);
      } else {
        Element expectedRoot = xpathSelectElement("/" + firstStep);
        if (expectedRoot == null)
          throw new ParseException("Existing root element <" + rootElement_.getTagName()
              + "...> does not match first step \"" + firstStep + "\" of \"" + xpath);
      }

      if (rootElemSteps.length == 0)
        return true;
      else
        return rootElement_.xpathEnsure(XPath.get(false, rootElemSteps).toString());

    } catch (XPathException e) {
      throw new ParseException(xpath, e);
    }
  }