java 中使用dom4j解析含有特殊字符的xml文件出现了如题的错误

这个时候需要在特殊字符外面加上

  1. <![CDATA[
  2. /6169220648+20671/1>7+-47390045<5+>*8<39><05+173*0>4253-->*4-1062//8-7>>>+8030004009
  3. ]]>

<?xml version="1.0" encoding="utf-8"?>
<TagYSIData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" IdentityFlag="0" Message="">
 <szFpTaxCtl>
 <![CDATA[
 /6169220648+20671/1>7+-47390045<5+>*8<39><05+173*0>4253-->*4-1062//8-7>>>+8030004009
]]>
</szFpTaxCtl>
 <szFpCode>234000610101</szFpCode>
 <szFpSeriaoNo>00425873</szFpSeriaoNo>
 <szFpMachineNo>929100040029</szFpMachineNo>
 <szFpDate>2007-04-30</szFpDate>
 <szFpCarrierID>340102760830197</szFpCarrierID>
 <szFpTaxDepCode>23401700080</szFpTaxDepCode>
 <szFpReceicerID>320281755076476</szFpReceicerID>
 <szFpSenderID>+340121149265576</szFpSenderID>
 <szFpAgentCode></szFpAgentCode>
 <szFpCarriageSum>3876.60</szFpCarriageSum>
 <szFpTax></szFpTax>
 <szFpKind>01</szFpKind>
 <szFpImage>F:\Files\Upload\022013101710011111111.jpg</szFpImage>
 <szFpWorkDir>D:\工作区\SVN项目\PCM(图片识别程序)\AppStart\scanDLL\TaxScan\dll2\Image\</szFpWorkDir>
 <szFpType></szFpType>
 <szFpRealID></szFpRealID>
 <szFpFromToAddr></szFpFromToAddr>
 <szFpTaxAll></szFpTaxAll>
 <szFpCarNum></szFpCarNum>
 <szFpCarTonnage></szFpCarTonnage>
 <szFpremarks></szFpremarks>
</TagYSIData>

然后java代码解析就不会出现问题

import java.io.File;
import java.util.Iterator;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 * XmlService.java
 * 版权所有(C) 2013
 * 创建:cuiran 2013-10-28 下午2:41:30
 */

/**
 * TODO
 * @author cuiran
 * @version 1.0.0
 */
public class XmlService {

public static void main(String[] args) {

		try{
			SAXReader reader = new SAXReader();
			Document document = reader.read(new File("E:\\022013101710011111111.xml")); 

			Element root = document.getRootElement();
			Iterator list  = root.elementIterator();
			while(list.hasNext())  {
				 Element resourceitem = (Element) list.next();
				 if(resourceitem.getName().equals("szFpTaxCtl")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpCode")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpSeriaoNo")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpMachineNo")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpDate")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpCarrierID")){
					 System.out.println(resourceitem.getData());
				 }

				 if(resourceitem.getName().equals("szFpTaxDepCode")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpReceicerID")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpSenderID")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpAgentCode")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpCarriageSum")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpTax")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpKind")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpImage")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpWorkDir")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpType")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpRealID")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpFromToAddr")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpTaxAll")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpCarNum")){
					 System.out.println(resourceitem.getData());
				 }
				 if(resourceitem.getName().equals("szFpCarTonnage")){
					 System.out.println(resourceitem.getData());
				 }

			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}

运行结果:

 /6169220648+20671/1>7+-47390045<5+>*8<39><05+173*0>4253-->*4-1062//8-7>>>+8030004009

234000610101
00425873
929100040029
2007-04-30
340102760830197
23401700080
320281755076476
+340121149265576

3876.60

01
F:\Files\Upload\022013101710011111111.jpg
D:\工作区\SVN项目\PCM(图片识别程序)\AppStart\scanDLL\TaxScan\dll2\Image\

The content of elements must consist of well-formed character data or markup的更多相关文章

  1. ibatis动态sql配置启动时提示:The content of elements must consist of well-formed character data...

    ibatis动态sql配置启动时提示:The content of elements must consist of well-formed character data... 2012-07-18 ...

  2. mybatis 报The content of elements must consist of well-formed character data or markup. 语法格式错误

    最近在写sql的时候 同时使用到了 >= 和 <= 之前只使用一个的时候 没有什么问题,今天同时使用到了两个,结果xml出现了The content of elements must co ...

  3. thymeleaf 解析html时,出现 SAXParseException: The content of elements must consist of well-formed characte

    thymeleaf 解析html时,出现 SAXParseException: The content of elements must consist of well-formed characte ...

  4. ibatis配置文件中的XML解析错误The content of elements must consist of well-formed character data or markup.

    在检查过所有的标签名都没有问题的情况下. xml中的小于号属于非法字符. SQL语句中则可能需要小于号,此时就需要用<![CDATA[  ]]>将小于号包裹,如此不会被xml解析器解析. ...

  5. ibatiS启动的异常 The content of elements must consist of well-formed character data or markup

    ibatiS启动的异常 The content of elements must consist of well-formed character data or markup 配置的动态SQL语句里 ...

  6. Cause: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.

    Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org ...

  7. Mybatis 异常: The content of elements must consist of well-formed character data or markup

    原因很简单:在ibatis的配置文件中不能出现小于号(>)     <delete id="deleteByPrimaryKey" parameterType=&quo ...

  8. MyBatis Sql语句中的转义字符

    1.在xml的sql语句中,不能直接用大于号.小于号要用转义字符 如果用小于号会报错误如下: org.apache.ibatis.builder.BuilderException: Error cre ...

  9. mybaits不能出现小于号

    org.xml.sax.SAXParseException; lineNumber: 146; columnNumber: 54; The content of elements must consi ...

随机推荐

  1. C++:如何删除string对象的末尾非数字字符

    功能实现: 现有一个string对象包含数字字符以及非数字字符,实现删除string对象的末尾非数字字符. 实例: 输入为"0 1 1 2 3    " 输出为"0 1 ...

  2. J2EE进阶(十四)超详细的Java后台开发面试题之Spring IOC与AOP

    J2EE进阶(十四)超详细的Java后台开发面试题之Spring IOC与AOP 前言   搜狐畅游笔试题中有一道问答题涉及到回答谈谈对Spring IOC与AOP的理解.特将相关内容进行整理.    ...

  3. Android Multimedia框架总结(十一)CodeC部分之AwesomePlayer到OMX服务

    转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼yuiop:http://blog.csdn.net/hejjunlin/article/details/52623882 前言:上篇文< ...

  4. Java提升篇之反射的原理

    Java提升篇之反射的原理 1.构造方法的反射 import java.lang.reflect.Constructor; public class ReflectConstructor { publ ...

  5. Linux2.6--虚拟文件系统

          虚拟文件系统(有时也称作虚拟文件交换,更常见的是简称做VFS)作为内核子系统,为用户空间程序提供了文件和文件系统相关的接口.系统中的所有文件系统不但依赖VFS共存,而且也依赖VFS系统协同 ...

  6. 对 jiffies 溢出、回绕及 time_after 宏的理解

    原文如下: 关于jiffies变量:     全局变量jiffies用来记录自启动以来产生的节拍的总数.系统启动时会将该变量初始化为0,此后,每当时钟中断产生时就会增加该变量的值.jiffies和另外 ...

  7. Java基础---集合框架---迭代器、ListIterator、Vector中枚举、LinkedList、ArrayList、HashSet、TreeSet、二叉树、Comparator

    为什么出现集合类? 面向对象语言对事物的体现都是以对象的形式,所以为了方便对多个对象的操作,就对对象进行存储,集合就是存储对象最常用的一种方式. 数组和集合类同是容器,有何不同? 数组虽然也可以存储对 ...

  8. oracle对大对象类型操作:blob,clob,nclob

     1.基本介绍 Oracle和plsql都支持lob(large object) 类型,用来存储大数量数据,如图像文件,声音文件等.Oracle 9i realse2支持存储最大为4g的数据,or ...

  9. Linux下jetty报java.lang.OutOfMemoryError: PermGen space及Jetty内存配置调优解决方案

    Linux下的jetty报java.lang.OutOfMemoryError: PermGen space及Jetty内存配置调优解决方案问题linux的jetty下发布程序后再启动jetty服务时 ...

  10. android scrollview嵌套listview计算高度的问题

    ScrollView中只能放一个控件,一般都放LinearLayout,orientation属性值为vertical.在LinearLayout中放需要呈现的内容.ListView也在其中,List ...