List of usage examples for org.jdom2.input SAXBuilder build
@Override public Document build(final String systemId) throws JDOMException, IOException
This builds a document from the supplied URI.
From source file:com.thoughtworks.xstream.io.xml.JDom2Driver.java
License:Open Source License
public HierarchicalStreamReader createReader(URL in) { try {//w w w .j a v a 2 s .co 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 ww . j a va 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 ww w. j a v a2s . c o 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 {//from w w w . ja v a 2 s . 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.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 av 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 www.j a v a2s . c om*/ 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 w ww. j a v a 2s. 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.javaToXML.java
public boolean creaAndValidaXML(TFactDocMX comprobante, String nombre) { boolean response = false; generaRaiz(comprobante);//from w w w.j av a 2 s .co m XMLOutputter outputter = new XMLOutputter(); File folder = new File("nativos"); folder.mkdirs(); Format formato = Format.getPrettyFormat(); formato.setEncoding("UTF-8"); outputter.setFormat(formato); File archivoXml = new File(nombre); try { //Writer write = new FileWriter(archivoXml); FileOutputStream fop = new FileOutputStream(archivoXml); outputter.output(getXml(), fop); } catch (IOException e) { System.err.println("e1:" + e); return response; } //se instancia la clase que validara el XSD SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true); builder.setFeature("http://apache.org/xml/features/validation/schema", true); builder.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true); builder.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", COMPROBANTE_SCHEMA_XSD); builder.setValidation(true); //se imprime el documento si se logro cumplir con el XSD try { Document document = builder.build(archivoXml); //outputter.output(document, System.out); response = true; } catch (JDOMException e) { System.out.println("e2:"); error = e.toString(); e.printStackTrace(); } catch (IOException e) { System.out.println("e3"); error = e.toString(); e.printStackTrace(); } return response; }
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 ww w .ja v a 2 s .c o m return configOverrides; }
From source file:converter.ConverterBean.java
private void init() throws MalformedURLException, JDOMException, IOException { if (isInit) { return;// w w w. j a v a 2 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"); } }