zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    关于lockkeyword
    关于多层for循环迭代的效率优化问题
    Android 面试精华题目总结
    Linux基础回想(1)——Linux系统概述
    linux源代码编译安装OpenCV
    校赛热身 Problem C. Sometimes Naive (状压dp)
    校赛热身 Problem C. Sometimes Naive (状压dp)
    校赛热身 Problem B. Matrix Fast Power
    校赛热身 Problem B. Matrix Fast Power
    集合的划分(递推)
  • 原文地址:https://www.cnblogs.com/diyunpeng/p/2394085.html
Copyright © 2011-2022 走看看