Item item;
if (Type.subTypeOf(type, Type.NODE)) {
item = (Item) child.getFirstChild();
if (type == Type.DOCUMENT) {
final NodeImpl n = (NodeImpl) item;
final DocumentBuilderReceiver receiver = new DocumentBuilderReceiver();
try {
receiver.startDocument();
n.getDocument().copyTo(n, receiver);
receiver.endDocument();
} catch (final SAXException e) {
throw new XPathException("Error while demarshalling node: " + e.getMessage(), e);
}
item = (Item) receiver.getDocument();
}
} else {
final StringBuilder data = new StringBuilder();
Node txt = child.getFirstChild();
while (txt != null) {