• <sub id="h4knl"><ol id="h4knl"></ol></sub>
    <sup id="h4knl"></sup>
      <sub id="h4knl"></sub>

      <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
      1. <strong id="h4knl"></strong>

      2. XML認證知識點:DOM Parser

        時間:2024-09-26 04:08:20 IBM認證 我要投稿
        • 相關推薦

        XML認證知識點:DOM Parser

          DOM Document 是以層次結構組織起來的節點,或信息片段的集合。這種層次結構允許開發者瀏覽樹來查找特定信息。通常,分析結構需要在完成任何工作之前裝入整個文檔并且裝入層次結構。

        XML認證知識點:DOM Parser

          基本的應用程序

          從創建基本的應用程序,名為 OrderProcessor 的類開始。

          import javax.xml.parsers.DocumentBuilder;

          import javax.xml.parsers.DocumentBuilderFactory;

          import java.io.File;

          import org.w3c.dom.Document;

          public class OrderProcessor {

          public static void main (String args[]) {

          File docFile = new File("orders.xml");

          Document doc = null;

          try {

          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

          DocumentBuilder db = dbf.newDocumentBuilder();

          doc = db.parse(docFile);

          } catch (Exception e) {

          System.out.print("Problem parsing the file.");

          }

          }

          }

          首先,Java 導入必要的類,然后創建 OrderProcessor 應用程序。在本教程中的這個示例將只處理一個文件,所以為簡短起見,該應用程序包含對它的直接引用。

          應用程序在 try-catch 塊外部定義了 Document 對象,以便在后面使用該對象。try-catch 使您能執行可能會拋出異常的一些操作,這樣不會危及整個應用程序。如果異常拋出,則應用程序簡單地執行相應的 catch 代碼。

          在 try-catch 塊內部,應用程序創建 DocumentBuilderFactory,然后使用它來創建 DocumentBuilder。最后,DocumentBuilder 解析該文件以創建 Document。

          編輯文檔

          更改節點數據

          Node.setNodeValue(elemValue);

          添加節點

          String totalString = new Double(total).toString();

          Node totalNode = doc.createTextNode(totalString);

          //Document 對象創建新的文本節點,該節點帶有作為值的 totalString

          Element totalElement = doc.createElement("total");

          //創建新元素 total

          totalElement.appendChild(totalNode);

          // 將節點添加到新的 total 元素。

          thisOrder.insertBefore(totalElement, thisOrder.getFirstChild());

          //將新元素添加到 Document,指定新的 Node,然后指定新 Node 在 Node 之前

          除去節點

          Node deadNode = thisOrderItem.getParentNode().removeChild(thisOrderItem);

          替換節點

          Element backElement = doc.createElement("backordered");

          //創建新元素 backordered

          Node deadNode = thisOrderItem.getParentNode().replaceChild(backElement,thisOrderItem);

          創建和設置屬性

          Element backElement = doc.createElement("backordered");

          //創建新元素 backordered

          backElement.setAttributeNode(doc.createAttribute("itemid"));

          //創建新屬性 itemid

          String itemIdString = thisOrderItem.getAttributeNode("itemid").getNodeValue();

          //取得thisOrderItem的屬性itemid的值

          backElement.setAttribute("itemid", itemIdString);

          //設置backElement的屬性item的值,可以省略createAttribute

          Node deadNode = thisOrderItem.getParentNode().replaceChild(backElement,thisOrderItem);

          除去屬性

          Element thisOrder = (Element)orders.item(orderNum);

          Element customer = (Element)thisOrder.getElementsByTagName("cusomertid").item(0);

          customer.removeAttribute("limit");

          //去除屬性limit

        《&.doc》
        将本文的Word文档下载到电脑,方便收藏和打印
        推荐度:
        点击下载文档

        【XML認證知識點:DOM Parser】相關文章:

        XML認證考試知識點:Parser08-21

        IBM XML認證知識點:Dtd09-01

        XML認證元素類型聲明05-28

        關于IBM XML認證考試的要點09-07

        ibm認證考試知識點08-05

        Linux認證考試必考知識點09-02

        華為認證:HCSE路由知識點羅列08-03

        關于HTML DOM的簡介10-16

        關于XML的介紹08-29

        Xml的英語解釋11-01

        在线咨询
        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码
      3. <sub id="h4knl"><ol id="h4knl"></ol></sub>
        <sup id="h4knl"></sup>
          <sub id="h4knl"></sub>

          <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
          1. <strong id="h4knl"></strong>

          2. 日韩精品一区二区三区影院 | 最新国产亚洲亚洲精 | 视频一区二区欧美 | 亚洲A∨精品一区二区三区 婷婷色婷婷开心五月 | 日韩一区二区三区四区五 | 天天精品福利一区视频 |

            XML認證知識點:DOM Parser

              DOM Document 是以層次結構組織起來的節點,或信息片段的集合。這種層次結構允許開發者瀏覽樹來查找特定信息。通常,分析結構需要在完成任何工作之前裝入整個文檔并且裝入層次結構。

            XML認證知識點:DOM Parser

              基本的應用程序

              從創建基本的應用程序,名為 OrderProcessor 的類開始。

              import javax.xml.parsers.DocumentBuilder;

              import javax.xml.parsers.DocumentBuilderFactory;

              import java.io.File;

              import org.w3c.dom.Document;

              public class OrderProcessor {

              public static void main (String args[]) {

              File docFile = new File("orders.xml");

              Document doc = null;

              try {

              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

              DocumentBuilder db = dbf.newDocumentBuilder();

              doc = db.parse(docFile);

              } catch (Exception e) {

              System.out.print("Problem parsing the file.");

              }

              }

              }

              首先,Java 導入必要的類,然后創建 OrderProcessor 應用程序。在本教程中的這個示例將只處理一個文件,所以為簡短起見,該應用程序包含對它的直接引用。

              應用程序在 try-catch 塊外部定義了 Document 對象,以便在后面使用該對象。try-catch 使您能執行可能會拋出異常的一些操作,這樣不會危及整個應用程序。如果異常拋出,則應用程序簡單地執行相應的 catch 代碼。

              在 try-catch 塊內部,應用程序創建 DocumentBuilderFactory,然后使用它來創建 DocumentBuilder。最后,DocumentBuilder 解析該文件以創建 Document。

              編輯文檔

              更改節點數據

              Node.setNodeValue(elemValue);

              添加節點

              String totalString = new Double(total).toString();

              Node totalNode = doc.createTextNode(totalString);

              //Document 對象創建新的文本節點,該節點帶有作為值的 totalString

              Element totalElement = doc.createElement("total");

              //創建新元素 total

              totalElement.appendChild(totalNode);

              // 將節點添加到新的 total 元素。

              thisOrder.insertBefore(totalElement, thisOrder.getFirstChild());

              //將新元素添加到 Document,指定新的 Node,然后指定新 Node 在 Node 之前

              除去節點

              Node deadNode = thisOrderItem.getParentNode().removeChild(thisOrderItem);

              替換節點

              Element backElement = doc.createElement("backordered");

              //創建新元素 backordered

              Node deadNode = thisOrderItem.getParentNode().replaceChild(backElement,thisOrderItem);

              創建和設置屬性

              Element backElement = doc.createElement("backordered");

              //創建新元素 backordered

              backElement.setAttributeNode(doc.createAttribute("itemid"));

              //創建新屬性 itemid

              String itemIdString = thisOrderItem.getAttributeNode("itemid").getNodeValue();

              //取得thisOrderItem的屬性itemid的值

              backElement.setAttribute("itemid", itemIdString);

              //設置backElement的屬性item的值,可以省略createAttribute

              Node deadNode = thisOrderItem.getParentNode().replaceChild(backElement,thisOrderItem);

              除去屬性

              Element thisOrder = (Element)orders.item(orderNum);

              Element customer = (Element)thisOrder.getElementsByTagName("cusomertid").item(0);

              customer.removeAttribute("limit");

              //去除屬性limit