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

  • 相关阅读:
    Javascript 闭包
    纯CSS实现侧边栏/分栏高度自动相等
    css实现16:9的图片比例
    CSS实现宽高成比例缩放
    div等比例缩放-------纯CSS实现自适应浏览器宽度的正方形
    websocket 实现简单网页版wechat
    Flask 简单使用,这一篇就够了!
    图灵机器人 V1 和 V2 接入方法
    Django中的cookie和session
    django 三件套(render,redirect,HttpResponse)
  • 原文地址:https://www.cnblogs.com/diyunpeng/p/2394085.html
Copyright © 2011-2022 走看看