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 ...
随机推荐
- FFmpeg源代码简单分析:avformat_close_input()
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
- android 选项卡TabHost
选项卡主要有TabHost.TabWiget和 FramentLayout3个组件组成,用于实现一个多标签的用户界面,通过他可以将一个复杂的对话分隔成若干个标签页,实现对信息的分类显示和管理.使用给组 ...
- 【IOS 开发】基本 UI 控件详解 (UISegmentedControl | UIImageView | UIProgressView | UISlider | UIAlertView )
转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/50163725 一. 分段控件 (UISegmentedControl) 控件展 ...
- 【原创】Nginx+PHP-FPM优化技巧总结
php-fpm的安装很简单,参见PHP(PHP-FPM)手动编译安装.下面主要讨论下如何提高Nginx+Php-fpm的性能. 1.Unix域Socket通信 之前简单介绍过Unix Domain S ...
- Docker教程:Docker镜像导出及迁移
http://blog.csdn.net/pipisorry/article/details/51330126 Docker目录分析 安装docker时,默认的安装位置是/var/lib/docker ...
- UNIX环境高级编程——线程同步之读写锁以及属性
读写锁和互斥量(互斥锁)很类似,是另一种线程同步机制,但不属于POSIX标准,可以用来同步同一进程中的各个线程.当然如果一个读写锁存放在多个进程共享的某个内存区中,那么还可以用来进行进程间的同步, 互 ...
- ROS(indigo)_pr2_simulator仿真(gazebo)示例
ROS(indigo)_pr2_simulator仿真(gazebo)示例 1 开启pr2仿真 ~$ roslaunch gazebo_ros empty_world.launch ~$ roslau ...
- iOS中 用FMDB封装一个SQLite数据库
建立一个单例: DataBaseHandle.h #import <Foundation/Foundation.h> @class PersonModel; @class FMDataba ...
- Cell自适应高度及自定义cell混合使…
第一部分:UItableViewCellAdaptionForHeight : cell的自适应高度 第二部分:CustomTableViewCell:自定义cell的混合使用(以简单通讯录为例) = ...
- Workflow相关表简单分析
静态定义表(没有ITEM_KEY,因为ITEM_KEY代表一个wf实例) --获取item_type定义. SELECT * FROM wf_item_types t WHEREt.name= 'CU ...