List of usage examples for org.jdom2 Document getRootElement
public Element getRootElement()
Element
for this Document
From source file:Contabilidad.CodeBase64.java
public void limpia(String ruta) { try {/*from ww w.j a va 2 s . c om*/ org.jdom2.Document doc = new SAXBuilder().build(ruta); Element rootNode = doc.getRootElement(); List list = rootNode.getContent(); for (int i = 0; i < list.size(); i++) { Content elementos = (Content) list.get(i); if (elementos.getCType() == Content.CType.Element) { Element aux = (Element) elementos; if (aux.getName().compareToIgnoreCase("Addenda") == 0) { List list2 = aux.getContent(); for (int j = 0; j < list2.size(); j++) { Content elementos2 = (Content) list2.get(j); if (elementos2.getCType() == Content.CType.Element) { Element aux2 = (Element) elementos2; if (aux2.getName().compareToIgnoreCase("FactDocMX") == 0) { list2.remove(aux2); } if (aux2.getName().compareToIgnoreCase("ECFD") == 0) { Namespace NP = Namespace.getNamespace("", ""); aux2.setNamespace(NP); List list3 = aux2.getContent(); for (int k = 0; k < list3.size(); k++) { Content elementos3 = (Content) list3.get(k); if (elementos3.getCType() == Content.CType.Element) { Element aux3 = (Element) elementos3; aux3.setNamespace(NP); List list4 = aux3.getContent(); for (int l = 0; l < list4.size(); l++) { Content elementos4 = (Content) list4.get(l); if (elementos4.getCType() == Content.CType.Element) { Element aux4 = (Element) elementos4; aux4.setNamespace(NP); List list5 = aux4.getContent(); for (int m = 0; m < list5.size(); m++) { Content elementos5 = (Content) list5.get(m); if (elementos5.getCType() == Content.CType.Element) { Element aux5 = (Element) elementos5; aux5.setNamespace(NP); List list6 = aux5.getContent(); for (int n = 0; n < list6.size(); n++) { Content elementos6 = (Content) list6.get(n); if (elementos6 .getCType() == Content.CType.Element) { Element aux6 = (Element) elementos6; aux6.setNamespace(NP); List list7 = aux6.getContent(); for (int p = 0; p < list7.size(); p++) { Content elementos7 = (Content) list7.get(p); if (elementos7 .getCType() == Content.CType.Element) { Element aux7 = (Element) elementos7; aux7.setNamespace(NP); List list8 = aux7.getContent(); for (int q = 0; q < list8.size(); q++) { Content elementos8 = (Content) list8 .get(q); if (elementos8 .getCType() == Content.CType.Element) { Element aux8 = (Element) elementos8; aux8.setNamespace(NP); } } } } } } } } } } } } List atributos = aux2.getAttributes(); for (int a = 0; a < atributos.size(); a++) { Attribute at = (Attribute) atributos.get(a); if (at.getName().compareToIgnoreCase("schemaLocation") == 0) aux2.removeAttribute(at); } } } } } } } XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); try { outputter.output(doc, new FileOutputStream(ruta)); } catch (IOException e) { System.out.println(e); } } catch (Exception e) { e.printStackTrace(); } }
From source file:controller.MobilePartnerController.java
public Map<String, Object> getConfiguredOverrides() throws Exception { Map<String, Object> configOverrides = new HashMap<>(); SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(DIR + "\\dbconf.xml"); Document document = (Document) builder.build(xmlFile); Element rootNode = document.getRootElement(); List<Element> list = rootNode.getChildren(); for (Element element : list) { configOverrides.put(element.getAttributeValue("name"), element.getText()); }/*from w ww . j av a2 s .co m*/ return configOverrides; }
From source file:converter.ConverterBean.java
private void init() throws MalformedURLException, JDOMException, IOException { if (isInit) { return;/* ww w.j a va2 s .c o m*/ } this.isInit = true; SAXBuilder sxb = new SAXBuilder(); { URL url = new URL("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"); Document document = sxb.build(url); racine = document.getRootElement(); Namespace ns = Namespace.getNamespace("http://www.ecb.int/vocabulary/2002-08-01/eurofxref"); racine = racine.getChild("Cube", ns); racine = racine.getChild("Cube", ns); } { URL url = new URL("http://www.currency-iso.org/dam/downloads/lists/list_one.xml"); Document document = sxb.build(url); racineMore = document.getRootElement(); racineMore = racineMore.getChild("CcyTbl"); } }
From source file:core.ValidXml.java
@Override public boolean validEstructura(File xml_file) { try {//from ww w . j a v a2s . c o m SAXBuilder builder = new SAXBuilder(); Document document = (Document) builder.build(xml_file); Element rootNode = document.getRootElement(); List list = (List) rootNode.getChildren(); Xml xml = new Xml(); for (Object object : list) { Element ob = (Element) object; System.out.println(ob.getName()); if (ob.getName().equalsIgnoreCase("autor")) { try { xml.getAutor().setNombre(ob.getChild("nombre").getText()); } catch (NullPointerException r) { xml.getAutor().setNombre(""); } try { xml.getAutor().setDescripcion(ob.getChild("descripcion").getText()); } catch (NullPointerException r) { xml.getAutor().setDescripcion(""); } try { xml.getAutor().setVersion(ob.getChild("version").getText()); } catch (NullPointerException r) { xml.getAutor().setVersion(""); } } else if (ob.getName().equalsIgnoreCase("cuerpo")) { try { Element tipo = ob.getChild("tipo"); xml.getCuerpo().setColumnas(Integer.parseInt(tipo.getAttribute("columnas").getValue())); xml.getCuerpo().setTipo_datos(tipo.getAttribute("tipodatocolumna").getValue().split(",")); } catch (NullPointerException r) { xml.getCuerpo().setColumnas(0); xml.getCuerpo().setTipo_datos(new String[] {}); } catch (NumberFormatException n) { xml.getCuerpo().setColumnas(0); xml.getCuerpo().setTipo_datos(new String[] {}); } try { Element tipo = ob.getChild("claseprincipal"); xml.getCuerpo().setMain(ob.getChild("claseprincipal").getValue()); } catch (NullPointerException r) { xml.getCuerpo().setMain(""); } ArrayList<String> parametros = new ArrayList<>(); try { System.out.println("*************** " + ob.getChild("parametro")); Element param = ob.getChild("parametro"); for (Element e : param.getChildren()) { System.out.println(e.getName()); try { System.out.println(e.getName()); parametros.add(e.getName()); } catch (NullPointerException r) { System.err.println("Se exploto"); } } } catch (NullPointerException r) { } finally { xml.getCuerpo().setParametros(parametros); } } } boolean respuesta = true; if (!xml.getAutor().getNombre().equals("")) { return false; } else if (xml.getCuerpo().getTipo_datos().length == 0) { return false; } else if (xml.getCuerpo().getParametros().size() == 0) { return false; } } catch (JDOMException ex) { Logger.getLogger(ValidXml.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ValidXml.class.getName()).log(Level.SEVERE, null, ex); } finally { } return true; }
From source file:core.xml.java
/** * @param args the command line arguments *//*from w w w. j a v a2 s .c o m*/ public static void main(String[] args) throws JDOMException { // TODO code application logic here SAXBuilder builder = new SAXBuilder(); File xmlFile = new File("/home/dark/Escritorio/Desde-Java/estructura.xml"); System.err.println(xmlFile); System.err.println(xmlFile.exists()); try { Document document = (Document) builder.build(xmlFile); Element rootNode = document.getRootElement(); List list = (List) rootNode.getChildren("configuracion"); extraerInformacion(list); System.err.println(descripcion); System.err.println(atributos); System.out.println(num_columnas); System.err.println(parametros); System.err.println(cabecera); } catch (IOException io) { System.err.println("Se exploto 1"); System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.err.println("Se exploto 2"); System.out.println(jdomex.getMessage()); } }
From source file:count_dep.AlanRitter.java
public void ACE2Alan() throws JDOMException, IOException { Properties props = new Properties(); props.put("annotators", "tokenize, ssplit"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); File corpus = new File("D:\\LDC2006D06\\LDC2006D06\\Data\\LDC2006T06_Original\\data\\English\\nw\\fp1"); File[] listFiles = corpus.listFiles(); for (File f : listFiles) { if (f.getName().endsWith(".sgm")) { PrintStream ps = new PrintStream(new FileOutputStream("D:\\ACEAlan\\" + f.getName())); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(f); Element foo = doc.getRootElement(); String text = foo.getChild("BODY").getChild("TEXT").getText(); Annotation document = new Annotation(text); pipeline.annotate(document); List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap cm : sentences) { String str = cm.toString(); String str2 = str.replace('\n', ' '); ps.println(str2);/* www . j a va 2 s . c o m*/ } ps.close(); } } }
From source file:count_dep.CountParagraph.java
public static LinkedList<String> GetSentences(File documentfile, StanfordCoreNLP pipeline) throws JDOMException, IOException { LinkedList<String> sentencelist = new LinkedList<>(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(documentfile); Element foo = doc.getRootElement(); String text = foo.getChild("BODY").getChild("TEXT").getText(); int titleend = text.indexOf("\n\n"); text = text.substring(titleend + 1).replace("\n\n", ". "); Annotation document = new Annotation(text); // run all Annotators on this text pipeline.annotate(document);/*from www . j a v a2 s. c o m*/ // these are all the sentences in this document // a CoreMap is essentially a Map that uses class objects as keys and has values with custom types List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap cm : sentences) { sentencelist.add(cm.toString()); } return sentencelist; }
From source file:count_dep.CountParagraph.java
private LinkedList<String> GetParagraphs(File documentfile) throws JDOMException, IOException { LinkedList<String> paralist = new LinkedList<>(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(documentfile); Element foo = doc.getRootElement(); String text = foo.getChild("BODY").getChild("TEXT").getText(); String[] split = text.split("\n\n"); for (int i = 0; i < split.length; i++) { paralist.add(split[i]);/* w ww .j av a 2 s . co m*/ } return paralist; }
From source file:count_dep.Count_dep.java
public static LinkedList<Event> ReadEvents(File f) throws JDOMException, IOException { LinkedList<Event> res = new LinkedList<>(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(f); Element foo = doc.getRootElement(); List<Element> one_document = foo.getChildren(); for (Element one_document1 : one_document) { List<Element> ERE = one_document1.getChildren(); for (Element e : ERE) { if ("event".equals(e.getName())) { List<Element> mentions = e.getChildren("event_mention"); for (Element m : mentions) { Event eve = new Event(); Element charseq; Element ldcscpope = m.getChild("ldc_scope"); charseq = ldcscpope.getChild("charseq"); eve.span = charseq.getText().replace("\n", " "); Element anchor = m.getChild("anchor"); charseq = anchor.getChild("charseq"); eve.trigger = charseq.getText(); if (eve.trigger.equalsIgnoreCase("saturday")) { int a = 0; a = a + 1;/*from w w w. jav a 2 s. c o m*/ } eve.eventtype = e.getAttribute("SUBTYPE").getValue(); eve.eventlargetype = e.getAttribute("TYPE").getValue(); List<Element> arguments = m.getChildren("event_mention_argument"); for (Element argu : arguments) { String argumentstr = argu.getChild("extent").getChild("charseq").getText(); if ("U.S".equals(argumentstr) || "U.N".equals(argumentstr) || "Feb".equals(argumentstr)) { argumentstr += "."; } if (argumentstr.equalsIgnoreCase("Basra")) { int a = 0; a = a + 1; } eve.arguments.add(new EventArgument(argumentstr, argu.getAttributeValue("ROLE"))); } eve.filename = f.getName(); res.add(eve); } } } } return res; }
From source file:count_dep.Count_dep.java
public static LinkedList<Event> ReadGrishmanEvents(File f) throws JDOMException, IOException { LinkedList<Event> res = new LinkedList<>(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(f); Element foo = doc.getRootElement(); List<Element> one_document = foo.getChildren(); for (Element one_document1 : one_document) { List<Element> ERE = one_document1.getChildren(); for (Element e : ERE) { if ("event".equals(e.getName())) { List<Element> mentions = e.getChildren("event_mention"); for (Element m : mentions) { Event eve = new Event(); eve.filename = f.getName(); Element charseq; Element anchor = m.getChild("anchor"); charseq = anchor.getChild("charseq"); eve.span = m.getChild("extent").getChild("charseq").getText(); eve.trigger = charseq.getText(); eve.eventtype = e.getAttribute("SUBTYPE").getValue(); List<Element> arguments = m.getChildren("event_mention_argument"); for (Element argu : arguments) { eve.arguments/* w ww. j a v a 2 s. com*/ .add(new EventArgument(argu.getChild("extent").getChild("charseq").getText(), argu.getAttributeValue("ROLE"))); } // eve.filename = f.getName(); res.add(eve); } } } } return res; }