/** * Converts a xom node into something readable by Saxon * * @param node * @param config * @return */ static NodeInfo wrap(Node node, Configuration config) { if (node == null) throw new IllegalArgumentException("node must not be null"); // $NON-NLS-1$ if (node instanceof DocType) throw new IllegalArgumentException("DocType can't be queried by XQuery/XPath"); // $NON-NLS-1$ Node root = node; while (root.getParent() != null) { root = root.getParent(); } DocumentWrapper docWrapper = new DocumentWrapper(root, root.getBaseURI(), config); return docWrapper.wrap(node); }
/** * Wrap or unwrap a node using this object model to return the corresponding Saxon node. If the * supplied source does not belong to this object model, return null */ public NodeInfo unravel(Source source, Configuration config) { if (source instanceof DOMSource) { Node dsnode = ((DOMSource) source).getNode(); if (!(dsnode instanceof NodeOverNodeInfo)) { // Supplied source is an ordinary DOM Node: wrap it Document dom; if (dsnode.getNodeType() == Node.DOCUMENT_NODE) { dom = (Document) dsnode; } else { dom = dsnode.getOwnerDocument(); } DocumentWrapper docWrapper = new DocumentWrapper(dom, source.getSystemId(), config); return docWrapper.wrap(dsnode); } } return null; }