{"id":240140,"date":"2022-04-22T08:57:31","date_gmt":"2022-04-22T00:57:31","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=240140"},"modified":"2022-04-11T10:59:12","modified_gmt":"2022-04-11T02:59:12","slug":"creation-node-overview","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/creation-node-overview.html","title":{"rendered":"XML DOM \u521b\u5efa\u8282\u70b9\u6982\u8ff0"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nXML DOM \u628a XML \u6587\u6863\u89c6\u4e3a\u4e00\u79cd\u6811\u7ed3\u6784\u3002\u8fd9\u79cd\u6811\u7ed3\u6784\u88ab\u79f0\u4e3a\u8282\u70b9\u6811\u3002\u53ef\u901a\u8fc7\u8fd9\u68f5\u6811\u8bbf\u95ee\u6240\u6709\u8282\u70b9\u3002\u53ef\u4ee5\u4fee\u6539\u6216\u5220\u9664\u5b83\u4eec\u7684\u5185\u5bb9\uff0c\u4e5f\u53ef\u4ee5\u521b\u5efa\u65b0\u7684\u5143\u7d20\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u521b\u5efa\u65b0\u7684\u5143\u7d20\u8282\u70b9<\/strong><\/div>\n

createElement() \u65b9\u6cd5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5143\u7d20\u8282\u70b9\uff1a<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

xmlDoc=loadXMLDoc(\"books.xml\");\r\nnewel=xmlDoc.createElement(\"edition\");\r\nx=xmlDoc.getElementsByTagName(\"book\")[0];\r\nx.appendChild(newel);<\/pre>\n

\u5b9e\u4f8b\u89e3\u91ca<\/strong>\uff1a<\/p>\n

    \n
  1. \u4f7f\u7528 loadXMLDoc() \u628a \"books.xml\" \u8f7d\u5165 xmlDoc \u4e2d<\/li>\n
  2. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5143\u7d20\u8282\u70b9 <edition><\/li>\n
  3. \u5411\u7b2c\u4e00\u4e2a <book> \u5143\u7d20\u8ffd\u52a0\u8fd9\u4e2a\u5143\u7d20\u8282\u70b9<\/li>\n<\/ol>\n
    \u521b\u5efa\u65b0\u7684\u5c5e\u6027\u8282\u70b9<\/strong><\/div>\n

    createAttribute() \u7528\u4e8e\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5c5e\u6027\u8282\u70b9\uff1a<\/p>\n

    \u5b9e\u4f8b<\/strong><\/p>\n

    xmlDoc=loadXMLDoc(\"books.xml\");\r\nnewatt=xmlDoc.createAttribute(\"edition\");\r\nnewatt.nodeValue=\"first\";\r\nx=xmlDoc.getElementsByTagName(\"title\");\r\nx[0].setAttributeNode(newatt);<\/pre>\n

    \u5b9e\u4f8b\u89e3\u91ca<\/strong>\uff1a<\/p>\n

      \n
    1. \u4f7f\u7528 loadXMLDoc() \u628a \"books.xml\" \u8f7d\u5165 xmlDoc \u4e2d<\/li>\n
    2. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5c5e\u6027\u8282\u70b9 \"edition\"<\/li>\n
    3. \u8bbe\u7f6e\u5c5e\u6027\u8282\u70b9\u7684\u503c\u4e3a \"first\"<\/li>\n
    4. \u5411\u7b2c\u4e00\u4e2a <title> \u5143\u7d20\u6dfb\u52a0\u8fd9\u4e2a\u65b0\u7684\u5c5e\u6027\u8282\u70b9<\/li>\n<\/ol>\n

      \u6ce8\u610f\uff1a\u5982\u679c\u8be5\u5c5e\u6027\u5df2\u5b58\u5728\uff0c\u5219\u88ab\u65b0\u5c5e\u6027\u66ff\u4ee3\u3002<\/p>\n

      \u4f7f\u7528 setAttribute() \u521b\u5efa\u5c5e\u6027<\/strong><\/div>\n

      \u7531\u4e8e setAttribute() \u65b9\u6cd5\u53ef\u4ee5\u5728\u5c5e\u6027\u4e0d\u5b58\u5728\u7684\u60c5\u51b5\u4e0b\u521b\u5efa\u65b0\u7684\u5c5e\u6027\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5c5e\u6027\u3002<\/p>\n

      \u5b9e\u4f8b<\/strong><\/p>\n

      xmlDoc=loadXMLDoc(\"books.xml\");\r\nx=xmlDoc.getElementsByTagName('book');\r\nx[0].setAttribute(\"edition\",\"first\");<\/pre>\n

      \u5b9e\u4f8b\u89e3\u91ca<\/strong>\uff1a<\/p>\n

        \n
      1. \u4f7f\u7528 loadXMLDoc() \u628a \"books.xml\" \u8f7d\u5165 xmlDoc \u4e2d<\/li>\n
      2. \u4e3a\u7b2c\u4e00\u4e2a <book> \u5143\u7d20\u8bbe\u7f6e\uff08\u521b\u5efa\uff09\u503c\u4e3a \"first\" \u7684 \"edition\" \u5c5e\u6027<\/li>\n<\/ol>\n
        \u521b\u5efa\u6587\u672c\u8282\u70b9<\/strong><\/div>\n

        createTextNode() \u65b9\u6cd5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u672c\u8282\u70b9\uff1a<\/p>\n

        \u5b9e\u4f8b<\/strong><\/p>\n

        xmlDoc=loadXMLDoc(\"books.xml\");\r\nnewel=xmlDoc.createElement(\"edition\");\r\nnewtext=xmlDoc.createTextNode(\"first\");\r\nnewel.appendChild(newtext);\r\nx=xmlDoc.getElementsByTagName(\"book\")[0];\r\nx.appendChild(newel);<\/pre>\n

        \u5b9e\u4f8b\u89e3\u91ca<\/strong>\uff1a<\/p>\n

          \n
        1. \u4f7f\u7528 loadXMLDoc() \u628a \"books.xml\" \u8f7d\u5165 xmlDoc \u4e2d<\/li>\n
        2. \u521b\u5efa\u4e00\u4e2a\u65b0\u5143\u7d20\u8282\u70b9 <edition><\/li>\n
        3. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u672c\u8282\u70b9\uff0c\u5176\u6587\u672c\u662f \"first\"<\/li>\n
        4. \u5411\u8fd9\u4e2a\u5143\u7d20\u8282\u70b9\u8ffd\u52a0\u65b0\u7684\u6587\u672c\u8282\u70b9<\/li>\n
        5. \u5411\u7b2c\u4e00\u4e2a <book> \u5143\u7d20\u8ffd\u52a0\u65b0\u7684\u5143\u7d20\u8282\u70b9<\/li>\n<\/ol>\n
          \u521b\u5efa CDATA Section \u8282\u70b9<\/strong><\/div>\n

          createCDATASection() \u65b9\u6cd5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 CDATA section \u8282\u70b9\u3002<\/p>\n

          \u5b9e\u4f8b<\/strong><\/p>\n

          xmlDoc=loadXMLDoc(\"books.xml\");\r\nnewCDATA=xmlDoc.createCDATASection(\"Special Offer & Book Sale\");\r\nx=xmlDoc.getElementsByTagName(\"book\")[0];\r\nx.appendChild(newCDATA);<\/pre>\n

          \u5b9e\u4f8b\u89e3\u91ca<\/strong>\uff1a<\/p>\n

            \n
          1. \u4f7f\u7528 loadXMLDoc() \u628a \"books.xml\" \u8f7d\u5165 xmlDoc \u4e2d<\/li>\n
          2. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684 CDATA section \u8282\u70b9<\/li>\n
          3. \u5411\u7b2c\u4e00\u4e2a <book> \u5143\u7d20\u8ffd\u52a0\u8fd9\u4e2a\u65b0\u7684 CDATA section \u8282\u70b9<\/li>\n<\/ol>\n
            \u521b\u5efa\u6ce8\u91ca\u8282\u70b9<\/strong><\/div>\n

            createComment() \u65b9\u6cd5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6ce8\u91ca\u8282\u70b9\u3002<\/p>\n

            \u5b9e\u4f8b<\/strong><\/p>\n

            xmlDoc=loadXMLDoc(\"books.xml\");\r\nnewComment=xmlDoc.createComment(\"Revised March 2008\");\r\nx=xmlDoc.getElementsByTagName(\"book\")[0];\r\nx.appendChild(newComment);<\/pre>\n

            \u5b9e\u4f8b\u89e3\u91ca<\/strong>\uff1a<\/p>\n

              \n
            1. \u4f7f\u7528 loadXMLDoc() \u628a \"books.xml\" \u8f7d\u5165 xmlDoc \u4e2d<\/li>\n
            2. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6ce8\u91ca\u8282\u70b9<\/li>\n
            3. \u628a\u8fd9\u4e2a\u65b0\u7684\u6ce8\u91ca\u8282\u70b9\u8ffd\u52a0\u5230\u7b2c\u4e00\u4e2a <book> \u5143\u7d20<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"

              createElement() \u65b9\u6cd5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5143\u7d20\u8282\u70b9\uff1a \u5b9e\u4f8b xmlDoc=loadXMLDoc(“boo […]<\/p>\n","protected":false},"author":1481,"featured_media":240125,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-240140","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/240140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1481"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=240140"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/240140\/revisions"}],"predecessor-version":[{"id":240145,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/240140\/revisions\/240145"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/240125"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=240140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=240140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=240140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}