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 ...
随机推荐
- Java多线程的调度策略
在Java多线程环境中,为保证所有线程的执行能按照一定的规则执行,JVM实现了一个线程调度器,它定义了线程调度的策略,对于CPU运算的分配都进行了规定,按照这些特定的机制为多个线程分配CPU的使用权. ...
- SQLite 运算符(http://www.w3cschool.cc/sqlite/sqlite-operators.html)
SQLite 运算符 SQLite 运算符是什么? 运算符是一个保留字或字符,主要用于 SQLite 语句的 WHERE 子句中执行操作,如比较和算术运算. 运算符用于指定 SQLite 语句中的条件 ...
- x264源代码简单分析:编码器主干部分-1
===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...
- MTK8127源码编译出现的错误及相关解决办法
/** * date:2016/8/17 * author: Y.X .YANG */ 按照开发文档提示: 1.MTK提供的开发包目录下有若干个.aa .ab .ac ...的分压缩包.此时应当将这些 ...
- UNIX网络编程——tcp流协议产生的粘包问题和解决方案
我们在前面曾经说过,发送端可以是一K一K地发送数据,而接收端的应用程序可以两K两K地提走数据,当然也有可能一次提走3K或6K数据,或者一次只提走几个字节的数据,也就是说,应用程序所看到的数据是一个整体 ...
- Android项目开发填坑记-9patchPng报错
如果阅读体验不佳,请使用–> Github版 背景 之前写了一篇文章Android必知必会–NinePatch图片制作详细介绍了Android 9Patch图片的制作和一些Demo展示,这次说明 ...
- (NO.00004)iOS实现打砖块游戏(十六):导弹发射道具的实现(下)
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 上一篇我们完成了导弹道具相关的道具制作,本篇中我们来完成其实现 ...
- Java中引用传递
//Java中的引用传递 class Ref1{ int temp = 10 ; String Str = "hello"; } public class HelloWorld { ...
- 【OpenCV文档】用于角点检测的Fast算法
原文地址:http://docs.opencv.org/trunk/doc/py_tutorials/py_feature2d/py_fast/py_fast.html#fast-algorithm- ...
- ntoskrnl符号在IDA中查看的问题
最近发现x64的ntoskrnl.exe,如果直接在IDA中查看,会有一些函数IDA没有识别出来,比如