dom4j

使用DOM4J生成XML文档

别等时光非礼了梦想. 提交于 2020-01-07 15:50:09
package xml; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; /** * @author xingsir * 使用DOM4J生成XML文档 */ public class WriteXmlDemo { public static void main(String[] args) { List<Dept> deptlist=new ArrayList<>(); deptlist.add(new Dept(1,"综合部","2020-01-01",400,"孙悟空")); deptlist.add(new Dept(2,"人事部","2020-01-01",400,"朱悟能")); deptlist.add(new Dept(3,"研发部","2020-01-01",400,"白龙马")); deptlist.add(new Dept(4,"销售部",

读取XML文件 Dom4j

家住魔仙堡 提交于 2020-01-07 01:09:06
读取xml public class Dom4jDemo { public static void main(String[] args) throws Exception{ /* * 使用 Dom4j API 读取XML文件 */ SAXReader reader=new SAXReader(); File file = new File("books.xml"); //利用SAXReader读取books.xml,如果读取成功就会创建一个dom对象 //其结构是树形的。如果读取失败则抛出异常: xml格式,文件找不到 Document doc=reader.read(file); //检查读取的结果 //System.out.println(doc.asXML()); //找到根元素, 作为访问入口 Element root = doc.getRootElement(); //root 就是 books 元素 //System.out.println(root.asXML()); //目标:显示全部的书名 //1. 获取全部子元素API List<Element> list=root.elements(); //for(Element e:list) { // System.out.println(e.asXML()); //} //2. 获取全部指定名称的子元素 list =

DOM解析手册

假如想象 提交于 2020-01-06 15:33:53
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> JAVA解析XML手册 XML文档以层级标签的形式来组织数据,多用于配置文件、存储静态数据、交换数据。 XML文档解析 首先我们要知道, “XML中的内容都是结点”, 这句话的意思是:XML文档中,无论是 <> </> 符号的里面的内容(属性)、之间的内容(结点值)、还是 <> 本身(结点),都是Node,就连标签之间的换行、空格都是一个节点。明白这个很重要,因为下面遍历结点时,返回的 属性名值对 、结点值内容、结点本身 都是一个Node类型。 实例 解析下面的XML文档 <?xml version="1.0" encoding="UTF-8" standalone="no"?> <users> <user userId="1001" idcard="370826199001133290"> <name>张三</name> <address>广州</address> <age>18</age> </user> <user userId="1002" idcard="370826199001133291"> <name>李四</name> <address>大连</address> <age>19</age> </user> ​ <user userId="1003" idcard=

Incorrect encoding in xml element using dom4j with Spring MVC

孤街醉人 提交于 2020-01-03 05:50:12
问题 I've created an AbstractView in order to output some XML to the browser, as follows: public abstract class AbstractXmlView extends AbstractView { public AbstractXmlView() { setContentType("application/xml"); } @Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setCharacterEncoding("UTF-8"); Document document = new DOMDocument(); document.setXMLEncoding("UTF-8"); buildXmlDocument

DOM4j doesn't work on Android

梦想与她 提交于 2019-12-25 03:13:06
问题 I try to use DOM4j to phase a XML RSS feed on Android. I do add the dom4j.jar to lib\ and the user permission. <uses-permission android:name="android.permission.INTERNET"/> I also compile this source code in pure Java project, and it works! I'm confused if there is any restrictions on Android(if yes, what methods can I use), or only I made some mistakes. Parts of Logcat: 03-15 23:27:10.611: W/System.err(10453): org.dom4j.DocumentException: Couldn't open http://tw.news.yahoo.com/rss/ Nested

How to get a list of String from Dom4j Node.selectObject or Node.selectNodes

*爱你&永不变心* 提交于 2019-12-24 02:27:09
问题 Hope you have a good day. The Dom4j javadoc form Node.selectObject(String xpathExpression) says the following: ...The object returned can either be a List of one or more Node instances or a scalar object like a String or a Number instance depending on the XPath expression. However when I try to get a list of String on this piece of xml: <root> ... <level1> <property>pro1</property> <property>pro1</property> <property>pro1</property> <level1> ... </root> with the following code: List result =

Using dom4j DOMDocument to feed validator.validate(DOMSource) fails in java 1.6 (xsi:noNamespaceSchemaLocation is not allowed), works in 1.5

眉间皱痕 提交于 2019-12-22 08:08:16
问题 Using dom4j DOMDocument to feed validator.validate(DOMSource) fails in java 1.6 (with xsi:noNamespaceSchemaLocation is not allowed to appear in root element), works in 1.5 I'm finding the following problem quite intractable (OK, that's an understatement) - any insights will be appreciated. Currently it seems like the best idea is to drop dom4j in favour of e.g. XOM (http://stackoverflow.com/questions/831865/what-java-xml-library-do-you-recommend-to-replace-dom4j). I've been validating in

XPATH problem with dom4j

一曲冷凌霜 提交于 2019-12-20 07:48:58
问题 I am using dom4j to overwrite a value in the XML. The XML looks like this: <start> <name color="blue" time="555555"> <element1 param="1"> <value>value1</value> <value>value2</value> <value>value3</value> <element1> </name> <name color="blue" time="888888"> <element2 param="1"> <value>value1</value> <value>value2</value> <value>value3</value> <element1> </name> </start> I am trying to semect nodes by: List list= document.selectNodes("//element1[@timetime='555555']" ); but the list returns null

java.lang.NoClassDefFoundError: org/dom4j/Document

筅森魡賤 提交于 2019-12-18 08:26:33
问题 I have a class called XMLtoXML.java and this is one of it's methods... import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.Node; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; public Object[] process(Object data) { String templateXML = null; Object result[] = null; String inputxml = null; String templateNumber = null; Iterator iterator = null; String scenarioConfigUrl = null; Node inputNode; Node outputNode; String subTemplateXML = null; String outputXml =

Caused by: java.lang.ClassNotFoundException: org.dom4j.io.STAXEventReader

最后都变了- 提交于 2019-12-17 14:27:18
问题 I am developing a web service application but sessionFactory bean is not creating because of below error. I can't see duplicate or conflict version of dom4j jar. I tried various times to referesh/clean server and project in eclipse. Hibernate version 5.1.0.Final Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-database.xml]: Invocation of init method failed; nested exception