zoukankan      html  css  js  c++  java
  • xml解析

    使用最原始的javax.xml.parsers,标准的jdk api

    // 字符串转XML
    String xmlStr = "......";
    StringReader sr = new StringReader(xmlStr); 
    InputSource is = new InputSource(sr); 
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
    DocumentBuilder builder=factory.newDocumentBuilder(); 
    Document doc = builder.parse(is);
    NodeList list = root.getChildNodes();
    //XML转字符串 TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); t.setOutputProperty("encoding","GB23121");//解决中文问题,试过用GBK不行 ByteArrayOutputStream bos = new ByteArrayOutputStream(); t.transform(new DOMSource(doc), new StreamResult(bos)); String xmlStr = bos.toString(); 这里的XML DOCUMENT为org.w3c.dom.Document

     

  • 相关阅读:
    函数和递归
    对象
    数组
    For...In 声明
    JavaScript 变量的生存期
    Hadoop Hive与Hbase整合+thrift
    朱子治家格言
    大学
    《孙子兵法》【谋攻第三】
    棋经十三篇
  • 原文地址:https://www.cnblogs.com/aeolian/p/7753104.html
Copyright © 2011-2022 走看看