private static @NotNull List<Element> extractNeededChildren(@NotNull Element element, @NotNull List<Element> remoteElements) {
    final String xpointer = element.getAttributeValue("xpointer");
    if (xpointer == null) {
      return remoteElements;
    }

    Matcher matcher = JDOMUtil.XPOINTER_PATTERN.matcher(xpointer);
    if (!matcher.matches()) {
      throw new XIncludeException("Unsupported XPointer: " + xpointer);
    }

    String pointer = matcher.group(1);
    matcher = JDOMUtil.CHILDREN_PATTERN.matcher(pointer);
    if (!matcher.matches()) {
      throw new XIncludeException("Unsupported pointer: " + pointer);
    }

    String rootTagName = matcher.group(1);

    assert remoteElements.size() == 1;
    Element e = remoteElements.get(0);
    if (!e.getName().equals(rootTagName)) {
      return Collections.emptyList();
    }

    String subTagName = matcher.group(2);
    if (subTagName != null) {
      // cut off the slash
      e = e.getChild(subTagName.substring(1));
      assert e != null;
    }
    return new ArrayList<>(e.getChildren());
  }
private static @NotNull List<Element> extractNeededChildren(@NotNull Element element, @NotNull List<Element> remoteElements)