<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                **1. 解析XML文檔** ```xml <students> <student order="001" id="zhangsan"> <name>張三</name> <age>25</age> 張三,你好! </student> <student order="002"> <name>李四</name> <age>28</age> 李四,你好! </student> </students> ``` ```java @Test public void read() throws ParserConfigurationException, IOException, SAXException { String xmlFile = this.getClass().getResource("/student.xml").getPath(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); File file = new File(xmlFile); //xml文檔 Document document = builder.parse(file); //所有的student節點 NodeList nodeList = document.getElementsByTagName("student"); Node node = nodeList.item(0); //節點名稱:student System.out.println("節點名稱:" + node.getNodeName()); //節點類型定義在接口Node中,如Node.ELEMENT_NODE //節點類型:1 System.out.println("節點類型:" + node.getNodeType()); Element element = (Element) node; //元素名:student System.out.println("元素名:" + element.getTagName()); //order屬性值:001 System.out.println("order屬性值:" + element.getAttribute("order")); //元素內的文本: // 張三 // 25 // 張三,你好! System.out.println("元素內的文本:" + element.getTextContent()); } ``` <br/> **2. 將XML文檔存入另一個新的文檔** ```java @Test public void transform() throws ParserConfigurationException, IOException, SAXException, TransformerException { String xmlFile = this.getClass().getResource("/student.xml").getPath(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); File file = new File(xmlFile); //xml文檔 Document document = builder.parse(file); TransformerFactory tranFactory = TransformerFactory.newInstance(); Transformer transformer = tranFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); Source xmlSource = new DOMSource(document); Result result = new StreamResult("e:/student2.xml"); transformer.transform(xmlSource, result); } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看