final Document incXmlDoc = DocumentHelper.createDocument(); final Element newRootNode = newXmlDoc.getRootElement(); final String packageName = newRootNode.attributeValue(XML_NODEATTR_PACKAGE); if (Utils.isNullOrNil(packageName)) { throw new TinkerPatchException("Unable to find package name from manifest: " + newFile.getAbsolutePath()); final Element newAppNode = newRootNode.element(XML_NODENAME_APPLICATION); final Element incAppNode = incXmlDoc.addElement(newAppNode.getQName()); copyAttributes(newAppNode, incAppNode); throw new TinkerPatchException("Parse android manifest error!"); } catch (DocumentException e) { e.printStackTrace(); throw new TinkerPatchException("Parse android manifest by dom4j error!"); } catch (IOException e) {
public void configure(String pluginName) { try { SAXReader saxReader = new SAXReader(); saxReader.setEncoding("UTF-8"); Document cacheXml = saxReader.read(configDataStream); List<Node> mappings = cacheXml.selectNodes("/cache-config/cache-mapping"); for (Node mapping: mappings) { registerCache(pluginName, mapping); } } catch (DocumentException e) { Log.error(e.getMessage(), e); } }
int loc = text.indexOf(" "); if (loc >= 0) { document.addProcessingInstruction(text.substring(0, loc), text.substring(loc + 1)); document.addProcessingInstruction(text, ""); parent.addComment(pp.getText()); document.addComment(pp.getText()); String text = pp.getText(); if (parent != null) { parent.addCDATA(text); throw new DocumentException("Cannot have text content outside of the root document"); String text = pp.getText(); if (parent != null) { parent.addText(text); throw new DocumentException("Cannot have an entityref outside of the root document"); throw new DocumentException("Cannot have text content outside of the root document");
DocumentException e2 = new DocumentException("Error parsing " + newFilename); e2.initCause(e); if (verbose) { e2.printStackTrace();
private Element loadXml(String fileName) { Element element = (Element) INCLUDED.get(fileName); if (element != null) return element; String content = read(fileName); SAXReader reader = new SAXReader(); StringReader stream = new StringReader(content); try { Element root = reader.read(stream).getRootElement(); INCLUDED.put(fileName, root); return root; } catch (DocumentException e) { logger.error("读取include指令指定的文件失败", e); throw new RuntimeException(e.getMessage(), e); } }
public DOM4JUtils(InputStream inputStream) { try { // document = reader.read(new // ByteArrayInputStream(xml.getBytes("UTF-8"))); document = new SAXReader().read(inputStream); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private String parseLiveUrl(ResponseBody responseBody) { String xml = null; try { xml = responseBody.string(); } catch (IOException e) { e.printStackTrace(); } LogUtil.d("xml", xml); Document document = null; try { document = DocumentHelper.parseText(xml); } catch (DocumentException e) { e.printStackTrace(); } assert document != null; Element rootElement = document.getRootElement(); Element durlElement = rootElement.element("durl"); Element urlElement = durlElement.element("url"); String url = urlElement.getText(); return url; } }
public String getType() { SAXReader saxReader = new SAXReader(); ByteArrayInputStream input = new ByteArrayInputStream(Message.getBytes()); Document document = null; try { document = saxReader.read(input); } catch (DocumentException ex) { ex.printStackTrace(System.out); } Element root = document.getRootElement(); Element tmp = root.element(MessageFields.MESSAGE_TYPE); return tmp.getText(); }
/** * Parses the specified {@link java.io.File}, using the given {@link * java.nio.charset.Charset}. * * @param file * the file to parse * @param charset * the charset to be used * * @return the resulting DOM4J document * * @throws DocumentException * when an error occurs while parsing */ public Document read(File file, Charset charset) throws DocumentException { try { Reader xmlReader = new InputStreamReader(new FileInputStream(file), charset); return getReader().read(xmlReader); } catch (JAXBRuntimeException ex) { Throwable cause = ex.getCause(); throw new DocumentException(cause.getMessage(), cause); } catch (FileNotFoundException ex) { throw new DocumentException(ex.getMessage(), ex); } }
@POST @Path("/toEditLogback/{workerId}") public Map<String, String> toEditLogback(@PathParam("workerId") String workerId) throws Throwable { logger.info("Receive a request to edit logback.xml, with workerId " + workerId); String path = System.getProperty("logback.configurationFile"); SAXReader reader = new SAXReader(); Map<String, String> result = new HashMap<>(); try { Document document = reader.read(new File(path)); result.put("content", document.asXML()); return result; } catch (DocumentException e) { logger.info("reading logback.xml error:", e); result.put("content", e.getMessage()); } return result; }
@Override public void run() { SAXReader reader = new SAXReader(); try { Document document = reader.read(new FileInputStream(infile)); Element root = document.getRootElement(); for (Iterator<Element> it = root.elementIterator(); it.hasNext(); ) { Element doc = it.next(); String file_path = doc.selectSingleNode("field[@name='localimagefile']").getText(); outStream.println(file_path); } } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } outStream.close(); } }
protected List<String> getSecurityRoles() { List<String> roles = new ArrayList<String>(); ServletContext sc = this.getServletContext(); InputStream is = sc.getResourceAsStream("/WEB-INF/web.xml"); try { SAXReader reader = new SAXReader(); Document doc = reader.read(is); Element webApp = doc.getRootElement(); // Type safety warning: dom4j doesn't use generics List<Element> roleElements = webApp.elements("security-role"); for (Element roleEl : roleElements) { roles.add(roleEl.element("role-name").getText()); } } catch (DocumentException e) { e.printStackTrace(); } return roles; }
result = xmlReader.read(responseReader); if ("error".equals(result.getRootElement().getName())) throw new ResponseException(result.getRootElement().getText()); throw new ResponseException(String.format("Failed to parse FishEye response: %s", XMLUtils.escape(e.getMessage())), e);
public static Element getRootElement(InputStream stream) throws DocumentException { try { SAXReader saxReader = new SAXReader(); saxReader.setEntityResolver(new DTDEntityResolver()); saxReader.setMergeAdjacentText(true); return saxReader.read(stream).getRootElement(); } catch (DocumentException e) { Throwable nested = e.getNestedException(); if (nested!= null) { if (nested instanceof FileNotFoundException) { throw new RuntimeException("Can't find schema/DTD reference: " + nested.getMessage(), e); } else if (nested instanceof UnknownHostException) { throw new RuntimeException("Cannot connect to host from schema/DTD reference: " + nested.getMessage() + " - check that your schema/DTD reference is current", e); } } throw e; } }
public static void main(String[] args) throws SAXException { String xml = "<root><item><errorCode>1</errorCode><errorDescription></errorDescription></item>"+"<item><errorCode>2</errorCode><errorDescription></errorDescription></item></root>"; SAXReader reader = new SAXReader(); Document doc = null; try { doc = reader.read(new ByteArrayInputStream(xml.getBytes())); @SuppressWarnings("unchecked") List<Element> list = doc.selectNodes("/root/item"); for(Element el : list){ Element errorCode = (Element) el.selectNodes("errorCode").get(0); Element errorDescription = (Element) el.selectNodes("errorDescription").get(0); System.out.println(errorCode.getText() + " : " + errorDescription.getText()); } }catch (DocumentException e) { e.printStackTrace(); } }
private static Document loadXML(InputStream in) throws IOException { try { // the SAXReader is closing the stream so that we need to copy the // content somewhere ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(in, baos); return new SAXReader().read(new ByteArrayInputStream(baos.toByteArray())); } catch (DocumentException e) { IOException ioe = new IOException("Failed to read log entry " + ": " + e.getMessage()); ioe.setStackTrace(e.getStackTrace()); throw ioe; } }
SAXReader reader = new SAXReader(); reader.setValidation(true); reader.setStripWhitespaceText(false); reader.setEntityResolver(new MyEntityResolver()); doc = reader.read(configuration); } catch (DocumentException e) { if (e.getNestedException() instanceof java.io.FileNotFoundException) { System.out.println("FileNotFoundException for configuration file: " + configuration); throw (java.io.FileNotFoundException) e.getNestedException(); e.printStackTrace();
/** {@inheritDoc} */ @Override public Element convert(String source) { try { return DocumentHelper.parseText(source).getRootElement(); } catch (DocumentException e) { throw new IllegalArgumentException("Failed to parse xml " + source + ", cause: " + e.getMessage(), e); } }
@Override public void onResponse(Call call, Response response) throws IOException { Document doc = null; try { doc = DocumentHelper.parseText(response.body().string()); } catch (DocumentException e) { e.printStackTrace(); } Element root = doc.getRootElement(); String recCode = root.elementText("code"); String recMsg = root.elementText("msg"); listener.onSuccess(recCode, recMsg, String.valueOf(smsCode)); Log.d(TAG,"-----验证码:"+smsCode); } });
Element elRoot = documentOld.getRootElement(); Element elRootCopy = (Element) elRoot.clone(); documentNew.add(elRootCopy); saxReader = new SAXReader(); document = saxReader.read(new File(pathname)); e.printStackTrace();