Refine search
SAXBuilder builder = new SAXBuilder(); try { Document document = (Document) builder.build(xmlString); Element rootNode = document.getRootElement(); List list = rootNode.getChildren("staff"); for (int i = 0; i < list.size(); i++) { Element node = (Element) list.get(i); System.out.println("First Name : " + node.getChildText("firstname")); System.out.println("Last Name : " + node.getChildText("lastname")); System.out.println("Nick Name : " + node.getChildText("nickname")); System.out.println("Salary : " + node.getChildText("salary")); } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); }
/** * <p>parseTypes.</p> * * @param content a {@link java.lang.String} object. * @return a {@link java.util.List} object. */ @SuppressWarnings("unchecked") public static final List<DataType> parseTypes(String content){ SAXBuilder reader = new SAXBuilder(); reader.setValidation(false); List<DataType> ret = new ArrayList<DataType>(); try{ Document doc = reader.build(new StringReader(content)); Element root = doc.getRootElement(); List<Element> types = root.getChildren(); for (int i=0; i<types.size(); i++){ Element elem = types.get(i); ret.add(parseType(elem)); } }catch(JDOMException e){ e.printStackTrace(); }catch(IOException e){ e.printStackTrace(); } return ret; }
private CassandraMappingManager() { keyspaceMap = new HashMap<String, Element>(); mappingMap = new HashMap<String, Element>(); try { loadConfiguration(); } catch (JDOMException e) { LOG.error(e.toString()); } catch (IOException e) { LOG.error(e.toString()); } }
private static Throwable getNestedException(Throwable parent) { if (parent instanceof JDOMException) { return ((JDOMException)parent).getCause(); Throwable nestedException = getNestedExceptionFromField(parent, "java.rmi.RemoteException", "detail"); if (nestedException != null) { return nestedException; nestedException = getNestedException(parent, "javax.naming.NamingException", "getRootCause"); if (nestedException != null) { return nestedException; nestedException = getNestedException(parent, "javax.servlet.ServletException", "getRootCause"); if (nestedException != null) { return nestedException;
private static Document readOverviewXml(String path) { SAXBuilder builder= new SAXBuilder(); File overviewFile= new File(path); if (!overviewFile.exists()) { System.err.println("Overview file doesn't exist: " + overviewFile.getAbsolutePath()); return null; } try { return builder.build(overviewFile); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
final Document doc = new SAXBuilder().build(file); final Element root = doc.getRootElement(); for (final Object o : root.getChildren("driver")) { final Element nameElement = ((Element) o).getChild("name"); names.add(nameElement.getValue()); final Element pathElement = ((Element) o).getChild("path"); "Error accessing key store: ", e.toString() }, "Error", JOptionPane.ERROR_MESSAGE); logger.error(e.getMessage(), e); } catch (final IOException e) { JOptionPane.showMessageDialog(null, new String[] {
public static String loadMetaInf(String key, String defValue) { try { InputStream in = CommonUtil.class.getClassLoader().getResourceAsStream("/META-INF/plugin.xml"); SAXBuilder builder = new SAXBuilder(); org.jdom.Document document = builder.build(in); return document.getRootElement().getChild(key).getContent().get(0).getValue(); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return defValue; }
@Override @NotNull public T deserialize( @NotNull InputStream in, @Nullable C context ) throws IOException, VersionMismatchException { try { Document document = new SAXBuilder().build( in ); ProcessingInstruction processingInstruction = getFormatInstruction( document ); Version formatVersion = parseVersion( processingInstruction ); Version.verifyMatch( getFormatVersion(), formatVersion ); return deserialize( document.getRootElement(), context ); } catch ( JDOMException e ) { throw new IOException( "Could not parse stream due to " + e.getMessage(), e ); } }
public Element serializeDataflow(Dataflow df) throws SerializationException { Element result = new Element(DATAFLOW, T2_WORKFLOW_NAMESPACE); result.setAttribute(DATAFLOW_ID,df.recordIdentifier()); try { Element name=new Element(NAME,T2_WORKFLOW_NAMESPACE); name.setText(df.getLocalName()); result.addContent(name); "There was a problem generating the XML for the workflow: " + jdomException.toString(), jdomException); } catch (IOException ioException) {
public JDomAnalyzer(InputSource input) throws JDOMException { SAXBuilder parser = new SAXBuilder(); try { doc = parser.build(input); } catch (JDOMException e) { throw e; } catch (IOException e) { throw new JDOMException("Cannot analyze this input", e); } }
private Element getFullConfigElement(){ SAXBuilder builder = new SAXBuilder(); builder.setIgnoringElementContentWhitespace(true); try { Document doc = builder.build("src/test/resources/main-config-full.xml"); return doc.getRootElement(); } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
Element getChannelElement(InputStream responseStream) throws IOException { try { SAXBuilder saxBuilder = SAXBuilderFactory.createSAXBuilder(); Document document = saxBuilder.build(responseStream); Element root = document.getRootElement(); if (root != null) { return root.getChild("channel"); } return null; } catch (JDOMException e) { log.error("Error while trying to assemble the issues returned in XML format: " + e.getMessage()); throw new IOException(e.getMessage()); } } }
Document root = builder.build(inFile); if (e.getCause() != null) Throwable rootCause = e.getCause(); if (rootCause instanceof SAXParseException) e.printStackTrace();
protected void reconcileEnrollmentSets(Document doc) { long start = System.currentTimeMillis(); if(log.isInfoEnabled()) log.info("Reconciling EnrollmentSets"); try { XPath docsPath = XPath.newInstance("/cm-data/enrollment-sets/enrollment-set"); List items = docsPath.selectNodes(doc); if(log.isDebugEnabled()) log.debug("Found " + items.size() + " enrollment sets to reconcile"); // Add or update each of the enrollment sets specified in the xml for(Iterator iter = items.iterator(); iter.hasNext();) { Element element = (Element)iter.next(); String eid = element.getChildText("eid"); if(log.isDebugEnabled()) log.debug("Reconciling enrollment set " + eid); EnrollmentSet enr = null; if(cmService.isEnrollmentSetDefined(eid)) { enr = updateEnrollmentSet(cmService.getEnrollmentSet(eid), element); } else { enr = addEnrollmentSet(element); } reconcileEnrollments(element.getChild("enrollments"), enr); reconcileOfficialInstructors(element, enr); } } catch (JDOMException jde) { log.error(jde.getMessage()); } if(log.isInfoEnabled()) log.info("Finished reconciling EnrollmentSets in " + (System.currentTimeMillis()-start) + " ms"); }
String groupID = file.getAttributeValue("GROUPID"); if (groupID == null || groupID.equals("")) { return null; if (oFiles.size() > 0) { if (log.isDebugEnabled()) { log.debug("Got ORIGINAL file for derived=" + file.toString()); Element flocat = ((Element) oFiles.get(0)).getChild("FLocat", metsNS); if (flocat != null) { return flocat.getAttributeValue("href", xlinkNS); log.warn("Got exception on XPATH looking for Original file, " + je.toString()); return null;
/** * @throws ValidationFailureException */ public Document parseAndValidateAgainstSchema(Reader reader) throws IOException { Preconditions.checkState(saxBuilder!=null,"SchemaSafeUnmarshaller: bean is uninitialized"); Document document = null; try { document = saxBuilder.build(reader); if (document.getRootElement().getNamespace() == null || StringUtils.isEmpty(document.getRootElement().getNamespace().getURI())) { throw new ValidationFailureException("document cannot be validated against schema, root Element has no namespace"); } if (!Objects.equal(namespace, document.getRootElement().getNamespace().getURI())) { throw new ValidationFailureException("document cannot be validated against schema, unexpected namespace ["+document.getRootElement().getNamespace().getURI()+"]"); } //System.out.println( XmlHelper.prettyFormat(document.getRootElement()) ); } catch (JDOMException e) { throw new ValidationFailureException(e.getClass().getSimpleName()+" - "+ e.getMessage()); } return document; }
String val = qdcProps.getProperty(qdc); try { Document d = builder.build(new StringReader(prolog + val + postlog)); Element element = (Element) d.getRootElement().getContent(0); qdc2element.put(qdc, element); element2qdc.put(makeQualifiedTagName(element), qdc); log.debug("Building Maps: qdc=\"" + qdc + "\", element=\"" + element.toString() + "\""); } catch (org.jdom.JDOMException je) { throw new CrosswalkInternalException( "Failed parsing XML fragment in properties file: \"" + prolog + val + postlog + "\": " + je .toString(), je);
/** * Parsowanie pliku xml i validacja zgodności ze schemą, <b>wejście: String</b>, * w przypadku błędu skłądni lub schemy, rzuca JDOMException. * * @param inFileContent Treść dokumentu do sparsowania * @param namespace pełna nazwa namespace, ex http://yadda.icm.edu.pl/bwmeta-2.1.0.xsd * @param schemaPath Lokalizacja schemy: classpath resource lub URL */ public static Document parse(byte[] inFileContent, String namespace, String schemaPath) throws JDOMException { Document doc = null; try { SAXBuilder builder = prepareBuilder(namespace, schemaPath); doc = builder.build(new ByteArrayInputStream(inFileContent)); } catch (JDOMException j) { logger.error("JDOMException: " + j.getMessage()); throw j; } catch (IOException e) { throw new RuntimeException(e.getClass().getName() + " - " + e.getMessage(),e); } logger.debug("Document parsed successfully, it's valid according to Schema: '"+schemaPath+"'"); return doc; }
/** * Initialize from text versions of QDC, XML and XPath. * The DC stays a string; parse the XML with appropriate * namespaces; "compile" the XPath. */ public static modsTriple create(String qdc, String xml, String xpath) { modsTriple result = new modsTriple(); final String prolog = "<mods xmlns:" + MODS_NS.getPrefix() + "=\"" + MODS_NS.getURI() + "\" " + "xmlns:" + XLINK_NS.getPrefix() + "=\"" + XLINK_NS.getURI() + "\">"; final String postlog = "</mods>"; try { result.qdc = qdc; result.xpath = XPath.newInstance(xpath); result.xpath.addNamespace(MODS_NS.getPrefix(), MODS_NS.getURI()); result.xpath.addNamespace(XLINK_NS); Document d = builder.build(new StringReader(prolog + xml + postlog)); result.xml = (Element) d.getRootElement().getContent(0); } catch (JDOMException je) { log.error("Error initializing modsTriple(\"" + qdc + "\",\"" + xml + "\",\"" + xpath + "\"): got " + je .toString()); return null; } catch (IOException je) { log.error("Error initializing modsTriple(\"" + qdc + "\",\"" + xml + "\",\"" + xpath + "\"): got " + je .toString()); return null; } return result; } }
/** * <p> * This builds a document from the supplied * filename. * </p> * * @param file <code>File</code> to read from * @return <code>Document</code> resultant Document object * @throws JDOMException when errors occur in parsing * @throws IOException when an I/O error prevents a document * from being fully parsed */ public Document build(File file) throws JDOMException, IOException { try { URL url = fileToURL(file); return build(url); } catch (MalformedURLException e) { throw new JDOMException("Error in building", e); } }