日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
如何正確使用PHPDOM-XML創(chuàng)建XML文件

我們?cè)趧?chuàng)建XML文件并對(duì)其進(jìn)行解析時(shí),通常都會(huì)用到PHP DOM-XML。那么如何才能正確的使用它來實(shí)現(xiàn)這一功能呢?下面我們就來仔細(xì)看下它的應(yīng)用方法。#t#

創(chuàng)新互聯(lián)建站為客戶提供專業(yè)的成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、程序、域名、空間一條龍服務(wù),提供基于WEB的系統(tǒng)開發(fā). 服務(wù)項(xiàng)目涵蓋了網(wǎng)頁設(shè)計(jì)、網(wǎng)站程序開發(fā)、WEB系統(tǒng)開發(fā)、微信二次開發(fā)、移動(dòng)網(wǎng)站建設(shè)等網(wǎng)站方面業(yè)務(wù)。

PHP DOM-XML的應(yīng)用代碼示例:

  1. < ?php
  2. /** 
  3. * Topic: Create and parse XML files using PHP DOM-XML 
  4. * Source:http://www.php.net/domxml 
  5. * Reference: http://www.zugeschaut-und-mitgebaut.de/php/extension.domxml.html 
  6. * Author:urs@circle.ch, 16-1-2001 
  7. */
  8. // 使用PHP DOM-XML創(chuàng)建和解析XML文件
  9. //創(chuàng)建XML文檔對(duì)象;以后的處理過程將在此基礎(chǔ)上進(jìn)行
  10. $doc = new_xmldoc("1.0" );
  11. //創(chuàng)建根節(jié)點(diǎn),并設(shè)置一個(gè)屬性
  12. $root = $doc->add_root("faq" );
  13. $root->setattr("page", "32" );
  14. //子節(jié)點(diǎn)
  15. $one = $root->new_child("question", "");
  16. //為子節(jié)點(diǎn)設(shè)置屬性
  17. $one->setattr("number", "1");
  18. //question也創(chuàng)建子節(jié)點(diǎn),并且給它賦值 
  19. $one->new_child("text", "1. Where to get libxml-2.0.0?");
  20. $one->new_child("answer", "You can download the latest 
  21. release of libxml either as a source archive or 
  22. RPM package from http://www.xmlsoft.org. 
  23. The current version is libxml2-2.2.1." );
  24. $two = $root->new_child("question", "" );
  25. $two->setattr("number", "2");
  26. $two->new_child("text", "2. How to configure PHP4?" );
  27. // 創(chuàng)建一個(gè)不直接賦值的節(jié)點(diǎn)
  28. $twoone = $two->new_child("answer", "");
  29. // 然后給它單獨(dú)賦值
  30. $twoone->set_content("DIR is the libxml install directory 
  31. (if you just use --with-dom it defaults 
  32. to /usr), I needed to use --with-dom=/usr/local" );
  33. $three = $root->new_child("question", "" );
  34. $three->setattr("number", "7" );
  35. $three->new_child("text", "7. How to use DOM XML function ?" );
  36. $three->new_child("answer", "Read this document source for 
  37. a simple example." );
  38. //輸出到Browser 
  39. print("< pre>".htmlspecialchars($doc->dumpmem() )."< /pre>" );
  40. // write to file
  41. //寫回到文件 
  42. $fp = fopen("test_dom.xml", "w+" );
  43. fwrite($fp, $doc->dumpmem(), strlen($doc->dumpmem() ));
  44. fclose($fp);
  45. //現(xiàn)在使用xpath從XML文檔中得到內(nèi)容
  46. $doc = xmldoc(join("", file("test_dom.xml")) );
  47. $ctx = xpath_new_context($doc );
  48. //所有對(duì)象
  49. $foo = xpath_eval($ctx, "http://child::*");
  50. print_r($foo);
  51. print("< br/>< br/>");
  52. //text node 對(duì)象
  53. $foo = xpath_eval($ctx, "http://text");
  54. print_r($foo);
  55. print("< br/>< br/>");
  56. // ***個(gè)text node對(duì)象
  57. $foo = xpath_eval($ctx, "http://text[1]");
  58. print_r($foo);
  59. print("< br/>< br/>");
  60. // 第二個(gè)text node對(duì)象
  61. $foo = xpath_eval($ctx, "http://text[2]");
  62. print_r($foo);
  63. print("< br/>< br/>");
  64. // 第三個(gè)answer對(duì)象
  65. $foo = xpath_eval($ctx, "http://answer[3]");
  66. print_r($foo);
  67. print("< br/>< br/>");
  68. //第三個(gè)text node的類型,名稱和內(nèi)容 
  69. $foo = xpath_eval($ctx, "http://text[3]");
  70. $tmp = $foo->nodeset;
  71. print_r($tmp);
  72. print("< br/>");
  73. print($tmp[0]->type) . "; ";
  74. print($tmp[0]->name) . "; ";
  75. print($tmp[0]->content);
  76. ?>

需要說明,PHP DOM-XML只能在PHPPHP4.0.x + linux上運(yùn)行


本文名稱:如何正確使用PHPDOM-XML創(chuàng)建XML文件
地址分享:http://m.5511xx.com/article/cdgpsii.html