void writeformattedItem(XdmItem item, ProcessContext context, OutputStream out) throws TransformerFactoryConfigurationError, TransformerException, IOException { if (item.isAtomicValue()) { out.write(item.getStringValue().getBytes(UTF8)); } else { // item is an XdmNode XdmNode node = (XdmNode) item; switch (node.getNodeKind()) { case DOCUMENT: case ELEMENT: Transformer transformer = TransformerFactory.newInstance().newTransformer(); final Properties props = getTransformerProperties(context); transformer.setOutputProperties(props); transformer.transform(node.asSource(), new StreamResult(out)); break; default: out.write(node.getStringValue().getBytes(UTF8)); } } }
private String getLang(XdmNode node) { String lang = null; while (lang == null && node.getNodeKind() == XdmNodeKind.ELEMENT) { lang = node.getAttributeValue(XProcConstants.xml_lang); node = node.getParent(); } return lang; } }
public static XdmNode makeNode(NodeInfo node) { return new XdmNode(node); }
private String extractText(XdmNode doc) { String content = ""; XdmSequenceIterator iter = doc.axisIterator(Axis.CHILD); while (iter.hasNext()) { XdmNode child = (XdmNode) iter.next(); if (child.getNodeKind() == XdmNodeKind.ELEMENT || child.getNodeKind() == XdmNodeKind.TEXT) { content += child.getStringValue(); } } return content; }
private static void dumpTreeNode(XdmNode node, String indent) { if (node.getNodeKind() == XdmNodeKind.ELEMENT) { System.err.println(indent + node.getNodeName() + ": " + node.getBaseURI()); XdmSequenceIterator iter = node.axisIterator(Axis.CHILD); while (iter.hasNext()) { XdmNode child = (XdmNode) iter.next(); dumpTreeNode(child, indent + " "); } } else if (node.getNodeKind() == XdmNodeKind.TEXT) { System.err.println(indent + "text: ..."); } }
private List<String> getMarkNames(XdmNode ssml){ XdmSequenceIterator iter = ssml.axisIterator(Axis.DESCENDANT); ArrayList<String> markNames = new ArrayList<String>(); while (iter.hasNext()){ XdmNode elt = (XdmNode) iter.next(); if (elt.getNodeKind() == XdmNodeKind.ELEMENT && "mark".equals(elt.getNodeName().getLocalName())){ markNames.add(elt.getAttributeValue(new QName("name"))); } } return markNames; }
public NamespaceBinding(XProcRuntime xproc, XdmNode node) { runtime = xproc; this.node = node; XdmSequenceIterator nsIter = node.axisIterator(Axis.NAMESPACE); while (nsIter.hasNext()) { XdmNode ns = (XdmNode) nsIter.next(); nsBindings.put((ns.getNodeName()==null ? "" : ns.getNodeName().getLocalName()),ns.getStringValue()); } }
@Test public void testPIPELINE() { AxisNodes an = new AxisNodes(null, root, Axis.CHILD, AxisNodes.PIPELINE); XdmNode n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("", "p")); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("", "p")); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.TEXT); assertEquals(n.toString(), " some text "); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("", "p")); assertEquals(an.iterator().hasNext(), false); } }
public static void dumpTree(XdmNode tree, String message) { NodeInfo treeNode = tree.getUnderlyingNode(); System.err.println(message); System.err.println("Dumping tree: " + treeNode.getSystemId() + ", " + tree.getBaseURI()); XdmSequenceIterator iter = tree.axisIterator(Axis.CHILD); while (iter.hasNext()) { XdmNode child = (XdmNode) iter.next(); dumpTreeNode(child, " "); } }
public XProcPipeline (XdmNode root) { pipeline = root; for (XdmNode node : new AxisNodes(runtime, root, Axis.CHILD, AxisNodes.PIPELINE)) { if (XProcConstants.p_input.equals(node.getNodeName())) { inputPorts.add(node.getAttributeValue(_port)); } if (XProcConstants.p_output.equals(node.getNodeName())) { outputPorts.add(node.getAttributeValue(_port)); } } } }
public static void assertDocument(XdmNode doc) { if (doc.getNodeKind() == XdmNodeKind.DOCUMENT) { S9apiUtils.assertDocumentContent(doc.axisIterator(Axis.CHILD)); } else if (doc.getNodeKind() == XdmNodeKind.ELEMENT) { // this is ok } else { throw XProcException.dynamicError(1, "Document root cannot be " + doc.getNodeKind()); } }
/** * The <code>equals()</code> relation between two XdmNode objects is true if they both represent the same * node. That is, it corresponds to the "is" operator in XPath. * * @param other the object to be compared * @return true if and only if the other object is an XdmNode instance representing the same node */ public boolean equals(Object other) { return other instanceof XdmNode && getUnderlyingNode().equals(((XdmNode) other).getUnderlyingNode()); }
@Override public Stream<XdmNode> apply(XdmItem item) { if (doc.getNodeKind() != XdmNodeKind.DOCUMENT) { throw new IllegalArgumentException("id() - argument is not a document node"); } NodeInfo target = doc.getUnderlyingNode().getTreeInfo().selectID(item.getStringValue(), true); return target==null ? Stream.empty() : Stream.of((XdmNode)XdmNode.wrap(target)); } };
public void addExtensionAttribute(XdmNode attr) { if (extnAttrs == null) { extnAttrs = new Hashtable<QName,String> (); } extnAttrs.put(attr.getNodeName(),attr.getStringValue()); }
public void processAttribute(XdmNode node) throws SaxonApiException { String value = node.getStringValue(); value = URIUtils.encode(value); URI baseURI = setBaseURI == null ? node.getBaseURI() : setBaseURI; String resolved = baseURI.resolve(value).toString(); matcher.addAttribute(node, resolved); } }
XdmValue matchList = xPathSelector.evaluate(); XdmItem firstItem = matchList.itemAt(0); if (firstItem instanceof XdmNode) { XdmNode xdmNode = (XdmNode) firstItem; XdmNodeKind nodeKind = xdmNode.getNodeKind(); if (nodeKind == XdmNodeKind.ELEMENT) { return xdmNode.toString(); } } return firstItem.getStringValue();
public PipelineLibrary useLibrary(XdmNode root) throws SaxonApiException { if (!XProcConstants.p_library.equals(root.getNodeName())) { throw new UnsupportedOperationException("Pipelines libraries must be p:library documents"); } if (declStack.isEmpty()) { topLevelImports.add(root.getBaseURI().toASCIIString()); } else { declStack.peek().addImport(root.getBaseURI().toASCIIString()); } return readLibrary(null, root); }
public static XdmNode getDocumentElement(XdmNode doc) { if (doc.getNodeKind() == XdmNodeKind.DOCUMENT) { for (XdmNode node : new AxisNodes(doc, Axis.CHILD, AxisNodes.SIGNIFICANT)) { if (node.getNodeKind() == XdmNodeKind.ELEMENT) { return node; // There can be only one, this is an XML document } } return null; } else { return doc; } }
private String compactSchema(XdmNode doc) { if ("base64".equals(doc.getAttributeValue(_encoding))) { byte[] decoded = Base64.decode(doc.getStringValue()); String s = new String(decoded); return s; } else { return doc.getStringValue(); } }
private void parseNamespaceBinding(XdmNode node) { String aname = node.getAttributeValue(_prefix); String avalue = node.getAttributeValue(_uri); nsBindings.put(aname, avalue); }