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

  • 相关阅读:
    Move site collections to a new database
    SharePoint 2010 Site Workflow
    Customizing the Server Ribbon
    [转]深入浅出之正则表达式
    asp.net中MD5加密写法代码
    asp.net中过滤非法字符防止SQL注入
    jQuery中ajax的使用方法
    gridview中用NewSelectedIndex获取选中的ID值
    GridView中得到选中的某行的ID值
    用javascript伪装链接地址状态代码
  • 原文地址:https://www.cnblogs.com/diyunpeng/p/2394085.html
Copyright © 2011-2022 走看看