Nodes included;
if (xpointer != null && xpointer.length() != 0) {
included = XPointer.query(doc, xpointer);
// fill in lang attributes here
for (int i = 0; i < included.size(); i++) {
Node node = included.get(i);
// Current implementation can only select elements
Element top = (Element) node;
Attribute lang = top.getAttribute("lang",
"http://www.w3.org/XML/1998/namespace");
if (lang == null) {
String childLanguage = getXMLLangValue(top);
if (!parentLanguage.equals(childLanguage)) {
top.addAttribute(new Attribute("xml:lang",
"http://www.w3.org/XML/1998/namespace",
childLanguage));
}
}
}
}
else {
included = new Nodes();
for (int i = 0; i < doc.getChildCount(); i++) {
Node child = doc.getChild(i);
if (!(child instanceof DocType)) {
included.append(child);
}
}
}
// so we can detach the old root if necessary
doc.setRootElement(new Element("f"));
for (int i = 0; i < included.size(); i++) {
Node node = included.get(i);
// Take account of xml:base attribute, which we normally
// don't do when detaching
String noFragment = node.getBaseURI();
if (noFragment.indexOf('#') >= 0) {
noFragment = noFragment.substring(0, noFragment.indexOf('#'));
}
node.detach();
if (node instanceof Element) {
((Element) node).setBaseURI(noFragment);
}
}