List of usage examples for org.jdom2.input SAXBuilder SAXBuilder
public SAXBuilder()
From source file:com.thoughtworks.xstream.io.xml.JDom2Driver.java
License:Open Source License
public HierarchicalStreamReader createReader(URL in) { try {/*from w ww . j a v a 2 s .c o m*/ SAXBuilder builder = new SAXBuilder(); Document document = builder.build(in); return new JDom2Reader(document, getNameCoder()); } catch (IOException e) { throw new StreamException(e); } catch (JDOMException e) { throw new StreamException(e); } }
From source file:com.thoughtworks.xstream.io.xml.JDom2Driver.java
License:Open Source License
public HierarchicalStreamReader createReader(File in) { try {/*from w w w.ja v a 2 s . com*/ SAXBuilder builder = new SAXBuilder(); Document document = builder.build(in); return new JDom2Reader(document, getNameCoder()); } catch (IOException e) { throw new StreamException(e); } catch (JDOMException e) { throw new StreamException(e); } }
From source file:com.ucuenca.dao.BaseXMLDao.java
public Table getTable() throws MalformedURLException, JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); URL url = new URL(path); InputStream stream = url.openStream(); Document document = null;//from w w w . j a v a2s . co m try { document = builder.build(stream); } catch (JDOMException e) { } Table table = new Table_Excel(); // Get Root Element and name Element root = document.getRootElement(); String rootName = root.getName(); // Get Second Level Elements, the rows of the data table List<Element> items = root.getChildren(); // Get column names, using the first element List<Element> firstItem = items.get(0).getChildren(); List<Column> columns = new ArrayList<Column>(); for (Element col : firstItem) { Column column = new Column(); column.setTitle(col.getName()); column.setStorageFormat(formatColumn(""));//pendiente columns.add(column); } // Get data and identify type data // for (Element item : items) { // ArrayList<String> row = new ArrayList<String>(); // for (Element col : item.getChildren()) { // row.add(col.getText()); // } // // } return table; }
From source file:com.versionmaintain.files.LastVersionInfosParser.java
License:Apache License
public List<VersionInfo> getVersionInfo() { SAXBuilder builder = new SAXBuilder(); List<VersionInfo> infos = new ArrayList<VersionInfo>(); try {// ww w .j a v a2s.c om Document doc = builder.build(new File(System.getProperty("user.dir") + File.separator + FILE_NAME)); Element root = doc.getRootElement(); List<Element> softEles = root.getChildren("software"); for (Element softEle : softEles) { String appName = softEle.getAttribute("name").getValue(); String versionCode = softEle.getChildText("latest-version-code"); String versionName = softEle.getChildText("latest-version"); Element detailEles = softEle.getChild("latest-version-detail"); List<Element> detailItemEles = detailEles.getChildren("item"); List<VersionInfoDetail> details = new ArrayList<VersionInfoDetail>(); for (Element detailItem : detailItemEles) { String title = detailItem.getAttributeValue("name"); List<Element> detailEleList = detailItem.getChildren("detail"); List<String> detailList = new ArrayList<String>(); for (Element detailEle : detailEleList) { String strDetail = detailEle.getText(); detailList.add(strDetail); } details.add(new VersionInfoDetail(title, detailList)); } VersionInfo versionInfo = new VersionInfo(); versionInfo.setAppName(appName); versionInfo.setVersion(versionName); versionInfo.setVersionCode(Integer.parseInt(versionCode)); versionInfo.setDetails(details); infos.add(versionInfo); } } catch (Exception e) { e.printStackTrace(); } return infos; }
From source file:com.webfront.app.utils.PDFImporter.java
private void getConfig() { jdomBuilder = new SAXBuilder(); String xmlSource = cfg.getInstallDir() + cfg.getFileSep() + "pnc.xml"; try {//w w w . ja v a 2 s . c om xmlDoc = jdomBuilder.build(xmlSource); Element root = xmlDoc.getRootElement(); List<Content> configContent = root.getContent(); List<Element> childElements = root.getChildren(); Element header = root.getChild("header"); for (Element e : header.getChildren()) { String content = e.getAttributeValue("content"); String format = e.getAttributeValue("format"); String text = e.getText(); } } catch (JDOMException ex) { Logger.getLogger(PDFImporter.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PDFImporter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.webfront.model.Config.java
public void getConfig() { jdomBuilder = new SAXBuilder(); try {//from w w w.jav a2s .c o m xmlDoc = jdomBuilder.build(getInstallDir() + getFileSep() + configFileName); Element docRoot = xmlDoc.getRootElement(); Element systemNode = docRoot.getChild("system"); installDir = systemNode.getChildText("installDir"); tmpDir = systemNode.getChildText("tmpDir"); } catch (FileNotFoundException ex) { //Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } catch (JDOMException ex) { Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.xebialabs.overcast.support.libvirt.JDomUtil.java
License:Apache License
/** Convert xml to JDOM2 {@link Document}. Throws {@link IllegalArgumentException} in case of errors. */ public static Document stringToDocument(String xml) { try {//from w w w .j a v a 2 s . c o m SAXBuilder sax = new SAXBuilder(); return sax.build(new ByteArrayInputStream(xml.getBytes("UTF-8"))); } catch (JDOMException e) { throw new IllegalArgumentException("Unable to parse xml", e); } catch (IOException e) { throw new IllegalArgumentException("Unable to parse xml", e); } }
From source file:compile.util.XMLUtil.java
public XMLUtil(String xmlPath) { _strPath = xmlPath;//from ww w. j a v a 2 s .c o m SAXBuilder sxb = new SAXBuilder(); try { _document = sxb.build(new File(_strPath)); _racine = _document.getRootElement(); } catch (Exception e) { System.out.println("Probleme de lecture avec le fichier XML"); } }
From source file:computeBase.ParseDataset.java
private ParseDataset() { //On cre une instance de SAXBuilder /*File file;/*from ww w . j a va 2 s .c o m*/ if(new File(path1 + "trainingset_uncomputed.xml").isFile()) { file = new File(path1 + "trainingset_uncomputed.xml"); } else { file = new File(path2 + "trainingset_uncomputed.xml"); }*/ File file; if (new File(path1 + "testingset_uncomputed.xml").isFile()) { file = new File(path1 + "testingset_uncomputed.xml"); } else { file = new File(path2 + "testingset_uncomputed.xml"); } SAXBuilder sxb = new SAXBuilder(); try { //On cre un nouveau document JDOM avec en argument le fichier XML //Le parsing est termin ;) document = sxb.build(file); } catch (IOException | JDOMException e) { throw new RuntimeException(e); } //On initialise un nouvel lment racine avec l'lment racine du document. drugs = document.getRootElement(); }
From source file:Contabilidad.CodeBase64.java
public void limpia(String ruta) { try {//w ww . ja v a2 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(); } }