SAX读取XML报错

控制台错误:

[Fatal Error] :7:6: The string "--" is not permitted within comments.

Exception in thread "main" org.xml.sax.SAXParseException: The string "--" is not permitted within comments.

    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

    at org.email.SaxTest.main(SaxTest.java:21)

 

java代码:

package org.email;

 

import java.io.FileReader;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.InputSource;

import org.xml.sax.SAXException;

import org.xml.sax.XMLReader;

import org.xml.sax.helpers.DefaultHandler;

import org.xml.sax.helpers.XMLReaderFactory;

 

public class SaxReadXml extends DefaultHandler {

    public static void main(String[] args) throws ParserConfigurationException,

           SAXException, IOException {

 

       XMLReader xr = XMLReaderFactory

              .createXMLReader("org.apache.xerces.parsers.SAXParser");

       xr.setContentHandler(new SaxReadXml());

       xr.parse(new InputSource(new FileReader(

              "D://WORK//SendEmail//src//Config.xml")));

    }

 

    public void characters(char[] ch, int start, int length)

           throws SAXException {

 

       String data = new String(ch, start, length);

       System.out.println("E-mail" + data);

 

    }

}

 

XML文档:

<?xml version="1.0" encoding="UTF-8"?>

<memory>

    <!--王小林-->

    <email>

       <receiver>81401592@qq.com</receiver>

    </email>

    <!-- me -->

    <email>

       <receiver>1058106015@qq.com</receiver>

    </email>

 

</memory>

 

原因分析:注意此处注释:<!--王小林-->与下方得区别<!-- me -->

 

王小林后面少了一个空格。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值