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. EJB_开发单表映射的实体bean

    开发单表映射的实体bean 实体bean 它属于java持久化规范(JPA)里的技术,实体bean通过元数据在Javabean和数据库表之间建立起映射关系,然后Java程序员就可以随心所欲的使用面向对 ...

  2. spring源码系列(一)sring源码编译 spring源码下载 spring源码阅读

    想对spring框架进行深入的学习一下,看看源代码,提升和沉淀下自己,工欲善其事必先利其器,还是先搭建环境吧. 环境搭建 sping源码之前是svn管理,现在已经迁移到了github中了,新版本基于g ...

  3. iOS 屏幕方向

    参考文章:http://www.tuicool.com/articles/e2q6zi 一般的应用,只会支持竖屏正方向一个方向,支持多个屏幕方向的应用还是比较少的. 当时也没搞明白,所以直接就设置了正 ...

  4. 关于android app签名文件获取sha1和MD值

    最近在做百度地图的嵌入,因为从同事接手的android app,所以第一次接触android的签名. 总的来说签名还比较简单,我用的是eclipse ADT自带的签名工具来做的签名,方法如下: 选择项 ...

  5. Java项目案例:酒店前台客服管理系统

    import java.util.Scanner; public class HelloWorld { public static void main(String[] args){ String [ ...

  6. 摆脱命令行,Ubuntu下配置Android开发环境

    作者:宋志辉 微博:weibo.com/askzhihui/ 安装所需工具 一.新立得 新立得(Synaptic)是Debian和Ubuntu Linux操作系统的包管理工具apt的图形化前端. 它结 ...

  7. Sql表注释

    1 创建表的时候写注释 create table test1 ( field_name int comment '字段的注释' )comment='表的注释'; 2 修改表的注释 alter tabl ...

  8. Ubuntu文件中文乱码

    如图,该文件在gedit打开中文显示正常 在命令行中用vim打开,显示内容如下: 使用命令进行编码转换 iconv -f gbk -t utf8 ./SogouQ.mini > ./sougou ...

  9. ISLR系列:(4.3)模型选择 PCR & PLS

    Linear Model Selection and Regularization 此博文是 An Introduction to Statistical Learning with Applicat ...

  10. 分布式进阶(十六)Zookeeper入门基础

    Zookeeper入门基础 前言 在Zookeeper中,znode是一个跟Unix文件系统路径相似的节点,可以往这个节点存储或获取数据.如果在创建znode时Flag设置为EPHEMERAL,那么当 ...