The content of elements must consist of well-formed character data or markup

java 中使用dom4j解析含有特殊字符的xml文件出现了如题的错误

这个时候需要在特殊字符外面加上

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TagYSIData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" IdentityFlag="0" Message="">  
  3.  <szFpTaxCtl>  
  4.  <![CDATA[  
  5.  /6169220648+20671/1>7+-47390045<5+>*8<39><05+173*0>4253-->*4-1062//8-7>>>+8030004009 
  6. ]]>   
  7. </szFpTaxCtl>  
  8.  <szFpCode>234000610101</szFpCode>  
  9.  <szFpSeriaoNo>00425873</szFpSeriaoNo>  
  10.  <szFpMachineNo>929100040029</szFpMachineNo>  
  11.  <szFpDate>2007-04-30</szFpDate>  
  12.  <szFpCarrierID>340102760830197</szFpCarrierID>  
  13.  <szFpTaxDepCode>23401700080</szFpTaxDepCode>  
  14.  <szFpReceicerID>320281755076476</szFpReceicerID>  
  15.  <szFpSenderID>+340121149265576</szFpSenderID>  
  16.  <szFpAgentCode></szFpAgentCode>  
  17.  <szFpCarriageSum>3876.60</szFpCarriageSum>  
  18.  <szFpTax></szFpTax>  
  19.  <szFpKind>01</szFpKind>  
  20.  <szFpImage>F:\Files\Upload\022013101710011111111.jpg</szFpImage>  
  21.  <szFpWorkDir>D:\工作区\SVN项目\PCM(图片识别程序)\AppStart\scanDLL\TaxScan\dll2\Image\</szFpWorkDir>  
  22.  <szFpType></szFpType>  
  23.  <szFpRealID></szFpRealID>  
  24.  <szFpFromToAddr></szFpFromToAddr>  
  25.  <szFpTaxAll></szFpTaxAll>  
  26.  <szFpCarNum></szFpCarNum>  
  27.  <szFpCarTonnage></szFpCarTonnage>  
  28.  <szFpremarks></szFpremarks>  
  29. </TagYSIData>  


然后java代码解析就不会出现问题

[java]  view plain copy
  1. import java.io.File;  
  2. import java.util.Iterator;  
  3.   
  4. import org.dom4j.Document;  
  5. import org.dom4j.Element;  
  6. import org.dom4j.io.SAXReader;  
  7.   
  8. /** 
  9.  * XmlService.java 
  10.  * 版权所有(C) 2013  
  11.  * 创建:cuiran 2013-10-28 下午2:41:30 
  12.  */  
  13.   
  14. /** 
  15.  * TODO 
  16.  * @author cuiran 
  17.  * @version 1.0.0 
  18.  */  
  19. public class XmlService {  
  20.   
  21. public static void main(String[] args) {  
  22.           
  23.         try{  
  24.             SAXReader reader = new SAXReader();    
  25.             Document document = reader.read(new File("E:\\022013101710011111111.xml"));   
  26.               
  27.             Element root = document.getRootElement();   
  28.             Iterator list  = root.elementIterator();  
  29.             while(list.hasNext())  {  
  30.                  Element resourceitem = (Element) list.next();  
  31.                  if(resourceitem.getName().equals("szFpTaxCtl")){  
  32.                      System.out.println(resourceitem.getData());  
  33.                  }  
  34.                  if(resourceitem.getName().equals("szFpCode")){  
  35.                      System.out.println(resourceitem.getData());  
  36.                  }  
  37.                  if(resourceitem.getName().equals("szFpSeriaoNo")){  
  38.                      System.out.println(resourceitem.getData());  
  39.                  }  
  40.                  if(resourceitem.getName().equals("szFpMachineNo")){  
  41.                      System.out.println(resourceitem.getData());  
  42.                  }  
  43.                  if(resourceitem.getName().equals("szFpDate")){  
  44.                      System.out.println(resourceitem.getData());  
  45.                  }  
  46.                  if(resourceitem.getName().equals("szFpCarrierID")){  
  47.                      System.out.println(resourceitem.getData());  
  48.                  }  
  49.                    
  50.                  if(resourceitem.getName().equals("szFpTaxDepCode")){  
  51.                      System.out.println(resourceitem.getData());  
  52.                  }  
  53.                  if(resourceitem.getName().equals("szFpReceicerID")){  
  54.                      System.out.println(resourceitem.getData());  
  55.                  }  
  56.                  if(resourceitem.getName().equals("szFpSenderID")){  
  57.                      System.out.println(resourceitem.getData());  
  58.                  }  
  59.                  if(resourceitem.getName().equals("szFpAgentCode")){  
  60.                      System.out.println(resourceitem.getData());  
  61.                  }  
  62.                  if(resourceitem.getName().equals("szFpCarriageSum")){  
  63.                      System.out.println(resourceitem.getData());  
  64.                  }  
  65.                  if(resourceitem.getName().equals("szFpTax")){  
  66.                      System.out.println(resourceitem.getData());  
  67.                  }  
  68.                  if(resourceitem.getName().equals("szFpKind")){  
  69.                      System.out.println(resourceitem.getData());  
  70.                  }  
  71.                  if(resourceitem.getName().equals("szFpImage")){  
  72.                      System.out.println(resourceitem.getData());  
  73.                  }  
  74.                  if(resourceitem.getName().equals("szFpWorkDir")){  
  75.                      System.out.println(resourceitem.getData());  
  76.                  }  
  77.                  if(resourceitem.getName().equals("szFpType")){  
  78.                      System.out.println(resourceitem.getData());  
  79.                  }  
  80.                  if(resourceitem.getName().equals("szFpRealID")){  
  81.                      System.out.println(resourceitem.getData());  
  82.                  }  
  83.                  if(resourceitem.getName().equals("szFpFromToAddr")){  
  84.                      System.out.println(resourceitem.getData());  
  85.                  }  
  86.                  if(resourceitem.getName().equals("szFpTaxAll")){  
  87.                      System.out.println(resourceitem.getData());  
  88.                  }  
  89.                  if(resourceitem.getName().equals("szFpCarNum")){  
  90.                      System.out.println(resourceitem.getData());  
  91.                  }  
  92.                  if(resourceitem.getName().equals("szFpCarTonnage")){  
  93.                      System.out.println(resourceitem.getData());  
  94.                  }  
  95.   
  96.             }  
  97.         }catch(Exception e){  
  98.             e.printStackTrace();  
  99.         }  
  100.     }  
  101. }  


运行结果:

[plain]  view plain copy
  1.     
  2.  /6169220648+20671/1>7+-47390045<5+>*8<39><05+173*0>4253-->*4-1062//8-7>>>+8030004009  
  3.    
  4.   
  5. 234000610101  
  6. 00425873  
  7. 929100040029  
  8. 2007-04-30  
  9. 340102760830197  
  10. 23401700080  
  11. 320281755076476  
  12. +340121149265576  
  13.   
  14. 3876.60  
  15.   
  16. 01  
  17. F:\Files\Upload\022013101710011111111.jpg  
  18. D:\工作区\SVN项目\PCM(图片识别程序)\AppStart\scanDLL\TaxScan\dll2\Image\  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值