List of usage examples for org.jdom2 Document getContent
@Override
public List<Content> getContent()
Document
. From source file:ca.nrc.cadc.caom2.xml.ObservationWriter.java
License:Open Source License
/** * Write the root Element to a writer.//www. ja v a2 s. co m * * @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); }
From source file:com.thoughtworks.go.server.service.lookups.CommandSnippetXmlParser.java
License:Apache License
private CommandSnippetComment getComment(Document document) { for (Object content : document.getContent()) { if (content instanceof Comment) { return new CommandSnippetTextComment(((Comment) content).getText()); }//from w w w . j a va2 s . c om } return new EmptySnippetComment(); }
From source file:de.hbrs.oryx.yawl.converter.handler.oryx.OryxDecompositionHandler.java
License:Open Source License
private Hashtable<String, String> convertParameterAttributes(final JSONObject jsonParam) throws ConversionException, JSONException { Hashtable<String, String> hashTable = new Hashtable<String, String>(); if (jsonParam.has("attributes") && !jsonParam.getString("attributes").isEmpty()) { Document attributes = YAWLUtils.parseToElement(jsonParam.getString("attributes")); for (Object obj : attributes.getContent()) { if (obj instanceof Element) { Element element = (Element) obj; hashTable.put(element.getName(), element.getText()); } else { getContext().addConversionWarnings("Attribute is not a JDOM Element", null); }/*from ww w. ja va 2 s . c om*/ } } return hashTable; }
From source file:eddpractica1_201503692.CargaXML.java
public void cargarXml(File xml) { //Parseo Arhchivo SAXBuilder builder = new SAXBuilder(); try {/*www .ja v a 2 s. c o m*/ //Se crea el documento a traves del archivo Document document = (Document) builder.build(xml); List elemento = document.getContent(); //Se obtiene la raiz 'tables' Element rootNode = document.getRootElement(); //Se obtiene la lista de hijos de la raiz 'tables' List list = rootNode.getChildren("diccionario"); List list1 = rootNode.getChildren("dobles"); //Se recorre la lista de hijos de 'tables' for (int i = 0; i < list.size(); i++) { //Se obtiene el elemento 'tabla' Element tabla = (Element) list.get(i); //Se obtiene el atributo 'nombre' que esta en el tag 'tabla' String nombreTabla = tabla.getValue(); System.out.println("Dimension: " + nombreTabla); //Se obtiene la lista de hijos del tag 'tabla' List lista_campos = tabla.getChildren(); //YA SE INSERTAN VALORES A LA LISTA SIMPLE PARA EL DICCIONARIO //Se recorre la lista de campos for (int j = 0; j < lista_campos.size(); j++) { //Se obtiene el elemento 'campo' Element campo = (Element) lista_campos.get(j); //Se obtienen los valores que estan entre los tags '<campo></campo>' //Se obtiene el valor que esta entre los tags '<nombre></nombre>' String nombre = campo.getValue(); lista.insertarAlFrente(nombre); //Se obtiene el valor que esta entre los tags '<tipo></tipo>' String tipo = campo.getChildTextTrim("y"); //Se obtiene el valor que esta entre los tags '<valor></valor>' // String valor = campo.getChildTextTrim("valor"); System.out.println("\t" + "x" + "\t\t" + "y"); System.out.println("\t" + nombre + "\t\t" + tipo + "\t\t"); System.out.println(lista.mostrarlista()); } } Palabras(); } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } }
From source file:org.apache.maven.io.util.AbstractJDOMWriter.java
License:Apache License
public final void write(final T source, final Document document, final Writer writer, final Format jdomFormat, final DocumentModifier modifier) throws java.io.IOException { if (modifier != null) { modifier.preProcess(document);//from w w w.j a v a 2 s . c om } update(source, new IndentationCounter(0), document.getRootElement()); if (modifier != null) { modifier.postProcess(document); } // Override XMLOutputter to correct initial comment trailing newlines. final XMLOutputter outputter = new XMLOutputter(new AbstractXMLOutputProcessor() { /** * This will handle printing of a {@link Document}. * * @param out <code>Writer</code> to use. * @param fstack the FormatStack * @param nstack the NamespaceStack * @param doc <code>Document</code> to write. * @throws IOException if the destination Writer fails */ @Override protected void printDocument(Writer out, FormatStack fstack, NamespaceStack nstack, Document doc) throws IOException { // If there is no root element then we cannot use the normal ways to // access the ContentList because Document throws an exception. // so we hack it and just access it by index. 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)); } } printDeclaration(out, fstack); Walker walker = buildWalker(fstack, list, true); if (walker.hasNext()) { while (walker.hasNext()) { final Content c = walker.next(); // we do not ignore Text-like things in the Document. // the walker creates the indenting for us. if (c == null) { // but, what we do is ensure it is all whitespace, and not CDATA final String padding = walker.text(); if (padding != null && Verifier.isAllXMLWhitespace(padding) && !walker.isCDATA()) { // we do not use the escaping or text* method because this // content is outside of the root element, and thus is not // strict text. write(out, padding); } } else { switch (c.getCType()) { case Comment: printComment(out, fstack, (Comment) c); // This modification we have made to the overridden method in order // to correct newline declarations. write(out, fstack.getLineSeparator()); break; case DocType: printDocType(out, fstack, (DocType) c); break; case Element: printElement(out, fstack, nstack, (Element) c); if (walker.hasNext()) { // This modification we have made to the overridden method in order // to correct newline declarations. write(out, fstack.getLineSeparator()); } break; case ProcessingInstruction: printProcessingInstruction(out, fstack, (ProcessingInstruction) c); break; case Text: final String padding = ((Text) c).getText(); if (padding != null && Verifier.isAllXMLWhitespace(padding)) { // we do not use the escaping or text* method because this // content is outside of the root element, and thus is not // strict text. write(out, padding); } default: // do nothing. } } } if (fstack.getLineSeparator() != null) { write(out, fstack.getLineSeparator()); } } } }); outputter.setFormat(jdomFormat); outputter.output(document, writer); }