private CommandSnippetComment getComment(Document document) { for (Object content : document.getContent()) { if (content instanceof Comment) { return new CommandSnippetTextComment(((Comment) content).getText()); } } return new EmptySnippetComment(); }
@Override public List<Content> cloneContent() { int size = getContentSize(); List<Content> list = new ArrayList<Content>(size); for (int i = 0; i < size; i++) { Content child = getContent(i); list.add(child.clone()); } return list; }
/** * Serialize out the Element. * * @serialData * <strong>Document Properties are not serialized!</strong> * <p> * The Stream protocol is: * <ol> * <li>The BaseURI using default Serialization. * <li>The count of child Content * <li>The actual Child Content. * </ol> * * @param out where to write the Element to. * @throws IOException if there is a writing problem. */ private void writeObject(final ObjectOutputStream out) throws IOException { out.defaultWriteObject(); final int cs = content.size(); out.writeInt(cs); for (int i = 0; i < cs; i++) { out.writeObject(getContent(i)); } }
final Content c = doc.getContent(i); org.w3c.dom.Node n = null; switch (c.getCType()) {
List<Content> content = resultdoc.getContent(); nodes = new ArrayList<Content>(content.size());
final Content c = document.getContent(i); out.getLocator().setNode(c); switch (c.getCType()) {
protected String getStyleSheet(final Document doc) { String styleSheet = null; for (final Content c : doc.getContent(new ContentFilter(ContentFilter.PI))) { final ProcessingInstruction pi = (ProcessingInstruction) c; if ("text/xsl".equals(pi.getPseudoAttributeValue("type"))) { styleSheet = pi.getPseudoAttributeValue("href"); break; } } return styleSheet; } }
List<Content> list = doc.hasRootElement() ? doc.getContent() : new ArrayList<Content>(doc.getContentSize()); if (list.isEmpty()) { final int sz = doc.getContentSize(); for (int i = 0; i < sz; i++) { list.add(doc.getContent(i));
protected String getStyleSheet(final Document doc) { String styleSheet = null; for (final Content c : doc.getContent(new ContentFilter(ContentFilter.PI))) { final ProcessingInstruction pi = (ProcessingInstruction) c; if ("text/xsl".equals(pi.getPseudoAttributeValue("type"))) { styleSheet = pi.getPseudoAttributeValue("href"); break; } } return styleSheet; } }
List<Content> list = doc.hasRootElement() ? doc.getContent() : new ArrayList<Content>(doc.getContentSize()); if (list.isEmpty()) { final int sz = doc.getContentSize(); for (int i = 0; i < sz; i++) { list.add(doc.getContent(i));
/** * Show iterating over a Document and printing some elements. * @param doc */ public static void demo(Document doc) { for (Object o : doc.getContent()) { if (o instanceof Element) { demo((Element) o); } else if (o instanceof Comment) doComment((Comment) o); else if (o instanceof ProcessingInstruction) doPI((ProcessingInstruction) o); } }
List<Content> list = doc.hasRootElement() ? doc.getContent() : new ArrayList<Content>(doc.getContentSize()); if (list.isEmpty()) { final int sz = doc.getContentSize(); for (int i = 0; i < sz; i++) { list.add(doc.getContent(i));
/** * Write the root Element to a writer. * * @param root Root Element to write. * @param writer Writer to write to. * @throws IOException if the writer fails to write. */ @SuppressWarnings("unchecked") protected void write(Element root, Writer writer) throws IOException { XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); Document document = new Document(root); if (stylesheetURL != null) { Map<String, String> instructionMap = new HashMap<String, String>(2); instructionMap.put("type", "text/xsl"); instructionMap.put("href", stylesheetURL); ProcessingInstruction pi = new ProcessingInstruction("xml-stylesheet", instructionMap); document.getContent().add(0, pi); } outputter.output(document, writer); } }
/** * Write to root Element to a writer. * * @param root Root Element to write. * @param writer Writer to write to. * @throws IOException if the writer fails to write. */ @SuppressWarnings("unchecked") protected void write(Element root, Writer writer) throws IOException { XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); Document document = new Document(root); if (stylesheetURL != null) { Map<String, String> instructionMap = new HashMap<String, String>(2); instructionMap.put("type", "text/xsl"); instructionMap.put("href", stylesheetURL); ProcessingInstruction pi = new ProcessingInstruction("xml-stylesheet", instructionMap); document.getContent().add(0, pi); } outputter.output(document, writer); }
List<Content> newContent = result.getContent();