The content of elements must consist of well-formed character data or markup
来源:互联网 发布:小区网络建设需求分析 编辑:程序博客网 时间:2024/06/02 07:34
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 234000610101004258739291000400292007-04-3034010276083019723401700080320281755076476+3401211492655763876.6001F:\Files\Upload\022013101710011111111.jpgD:\工作区\SVN项目\PCM(图片识别程序)\AppStart\scanDLL\TaxScan\dll2\Image\
- The content of elements must consist of well-formed character data or markup.
- mybatis异常:The content of elements must consist of well-formed character data or markup.
- The content of elements must consist of well-formed character data or markup
- The content of elements must consist of well-formed character data or markup
- The content of elements must consist of well-formed character data or markup
- Mybatis 异常: The content of elements must consist of well-formed character data or markup
- mybatis:The content of elements must consist of well-formed character data or markup
- The content of elements must consist of well-formed character data or markup
- 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
- mybatis 提示The content of elements must consist of well-formed character data or markup
- MyBatis报错:The content of elements must consist of well-formed character data or markup.
- Mybatis 异常: The content of elements must consist of well-formed character data or markup
- The content of elements must consist of well-formed character data or markup.
- 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
- mybatis 提示The content of elements must consist of well-formed character data or markup
- The content of elements must consist of well-formed character data or markup.
- Java 环境变量配置
- 简述Ubuntu Server修改IP/DNS
- form 表单域的动态设计-customized tab information 模块代码开发总结(1)
- mysql查询语句
- win7(64位)彻底卸载mysql,重装不再烦恼
- The content of elements must consist of well-formed character data or markup
- fatal error LNK1207
- 内存单元和内存单元地址
- jquerymobile脚本编写经验
- eclipse_php配置
- android wifi讲解 wifi列表显示
- 数据库基本操作SQL(创建表 添加主键 添加列的常用语句)
- UEFI PCI Bus Driver分析
- ROS的学习(三)创建一个工作空间