The content of elements must consist of well-formed character data or markup
java 中使用dom4j解析含有特殊字符的xml文件出现了如题的错误
这个时候需要在特殊字符外面加上
- <![CDATA[
- /6169220648+20671/1>7+-47390045<5+>*8<39><05+173*0>4253-->*4-1062//8-7>>>+8030004009
- ]]>
<?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的更多相关文章
- 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 ...
- mybatis 报The content of elements must consist of well-formed character data or markup. 语法格式错误
最近在写sql的时候 同时使用到了 >= 和 <= 之前只使用一个的时候 没有什么问题,今天同时使用到了两个,结果xml出现了The content of elements must co ...
- 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 ...
- ibatis配置文件中的XML解析错误The content of elements must consist of well-formed character data or markup.
在检查过所有的标签名都没有问题的情况下. xml中的小于号属于非法字符. SQL语句中则可能需要小于号,此时就需要用<![CDATA[ ]]>将小于号包裹,如此不会被xml解析器解析. ...
- 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语句里 ...
- 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 ...
- Mybatis 异常: The content of elements must consist of well-formed character data or markup
原因很简单:在ibatis的配置文件中不能出现小于号(>) <delete id="deleteByPrimaryKey" parameterType=&quo ...
- MyBatis Sql语句中的转义字符
1.在xml的sql语句中,不能直接用大于号.小于号要用转义字符 如果用小于号会报错误如下: org.apache.ibatis.builder.BuilderException: Error cre ...
- mybaits不能出现小于号
org.xml.sax.SAXParseException; lineNumber: 146; columnNumber: 54; The content of elements must consi ...
随机推荐
- ROS_Kinetic_27 在ROS中使用Cartographer进行SLAM
ROS_Kinetic_27 在ROS中使用Cartographer进行SLAM Cartographer是谷歌新開源的通用的2D和3D定位與構圖同步的SLAM工具,並提供ROS接口. 论文Real- ...
- JAR、WAR、EAR的使用和区别
最近接触这几个词较多,停下来总结总结它们的区别和联系,更好的深刻理解 Jar.war.EAR.在文件结构上,三者并没有什么不同,它们都采用zip或jar档案文件压缩格式.但是它们的使用目的有所区别: ...
- 一个 Linux 上分析死锁的简单方法
简介 死锁 (deallocks): 是指两个或两个以上的进程(线程)在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去.此时称系统处于死锁状态或系统产生了死锁,这 ...
- Dynamics CRM 自定义上传附件的图片悬浮层显示
CRM中的附件是以流的形式保存在了数据库中,这样做的一个坏处是一旦系统运行时间久,附件上传的多了势必会导致数据库极速扩大,即影响系统的运行效率也对后期的迁移维护带来了不必要的麻烦.所以很多的客户都会要 ...
- 18 Loader 总结
1. Loader 装载器 Android3.0以后出来的 它可以使Activity和Fragment 异步加载数据 变得简单(Loader里封装了AsyncTask) Loader特点: 1,对每一 ...
- [struts2学习笔记] 第二节 使用Maven搞定管理和构造Struts 2 Web应用程序的七个步骤
本文地址:http://blog.csdn.net/sushengmiyan/article/details/40303897 官方文档:http://struts.apache.org/releas ...
- (一〇三)静态库(.a)的调试
上节介绍的方法,只能创建静态库而不能调试,因为直接创建静态库工程并非可执行文件. 本文介绍的方法创建的静态库断点能够在调试时起作用. 为了能够调试静态库,应该在一个可执行工程(例如Single Vie ...
- 详解EBS接口开发之库存事务处理批次更新
库存事务处理批次有时候出现导入错误需要更新可使用次程序更新,批次导入可参考博客 详解EBS接口开发之库存事务处理-物料批次导入 http://blog.csdn.net/cai_xingyun/art ...
- 使用jquery获取radio的值
使用jquery获取radio的值,最重要的是掌握jquery选择器的使用,在一个表单中我们通常是要获取被选中的那个radio项的值,所以要加checked来筛选,比如有以下的一些radio项: ...
- TableEdit UI_10
1.tableView的编辑的步骤: 1.让tableView处于编辑状态,(默认所有的cell都处于编辑状态,默认下的编辑样式是删除) 2.设置哪些cell可以编辑 3.设置编辑的样式(删除,插 ...