• org.dom4j.DocumentException: no protocol 规格严格


    /**
     * Test
     * <p>
     * Date: 2012-03-13,16:25:20 +0800
     *
     * @version 1.0
     */
    public class Test {

        /**
         * @param args
         */
        public static void main(String[] args) {

            try {
                File f = new File("c:\\a.xml");
                BufferedReader rr = new BufferedReader(new InputStreamReader(
                    new FileInputStream(f)));
                StringBuffer buf = new StringBuffer();
                String txt = rr.readLine();
                while (txt != null) {
                    buf.append(txt).append("\n");
                    txt = rr.readLine();
                }

                /**
                 * API 使用错误
                 */
                SAXReader saxReader = new SAXReader();
                Document document = saxReader.read(new ByteArrayInputStream(buf
                    .toString().getBytes("utf-8")));
                List<?> policyNodes = document.selectNodes("//PolicyList/Policy");
                if (policyNodes != null && policyNodes.size() != 0) {
                    List<String> policys = new ArrayList<String>();
                    for (int i = 0; i < policyNodes.size(); i++) {
                        Element e = (Element) policyNodes.get(i);
                        policys.add(e.attributeValue("ID"));
                    }
                    System.out.println(policys);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (DocumentException e) {
                e.printStackTrace();
            }

        }
    }

    错误发生的很不应该,我直接用

    saxReader.read(xml)了,事实上read接受xml时候的参数含义为systemId,唉,API啊。。人要仔细。。。老了


    引用一下这篇:

    http://blog.csdn.net/luo_yifan/article/details/6442618

  • 相关阅读:
    防止表单重复提交的几种策略
    Linux模块
    ASP.Net MVC3 图片上传详解(form.js,bootstrap)
    在ASP.NET MVC3 中利用Jsonp跨域访问
    C# 利用反射动态创建对象——带参数的构造函数和String类型
    第一章 CLR 的执行模型
    Linux Shell脚本攻略 读书笔记
    使用MVC4,Ninject,EF,Moq,构建一个真实的应用电子商务SportsStore
    验证码识别的一些总结及相关代码
    使用DateTime的ParseExact方法实现特殊日期时间的方法详解(转)
  • 原文地址:https://www.cnblogs.com/diyunpeng/p/2394085.html
Copyright © 2020-2023  润新知