国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > XML > 正文

使用PHP DOM-XML創(chuàng)建和解析XML文件

2024-09-05 20:54:08
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

使用PHP DOM-XML創(chuàng)建和解析XML文件
<?php
/**
* Topic: Create and parse XML files using PHP DOM-XML
* Source:http://www.php.net/domxml
* Reference: http://www.zugeschaut-und-mitgebaut.de/php/extension.domxml.html
* Author:urs@circle.ch, 16-1-2001
*
*/
// 使用PHP DOM-XML創(chuàng)建和解析XML文件

//創(chuàng)建XML文檔對(duì)象;以后的處理過(guò)程將在此基礎(chǔ)上進(jìn)行
$doc = new_xmldoc("1.0" );

//創(chuàng)建根節(jié)點(diǎn),并設(shè)置一個(gè)屬性
$root = $doc->add_root("faq" );
$root->setattr("page", "32" );

//子節(jié)點(diǎn)
$one = $root->new_child("question", "");
//為子節(jié)點(diǎn)設(shè)置屬性
$one->setattr("number", "1");
//question也創(chuàng)建子節(jié)點(diǎn),并且給它賦值
$one->new_child("text", "1. Where to get libxml-2.0.0?");
$one->new_child("answer", "You can download the latest
release of libxml either as a source archive or
RPM package from http://www.xmlsoft.org.
The current version is libxml2-2.2.1." );

$two = $root->new_child("question", "" );
$two->setattr("number", "2");
$two->new_child("text", "2. How to configure PHP4?" );
// 創(chuàng)建一個(gè)不直接賦值的節(jié)點(diǎn)
$twoone = $two->new_child("answer", "");
// 然后給它單獨(dú)賦值
$twoone->set_content("DIR is the libxml install directory
(if you just use --with-dom it defaults
to /usr), I needed to use --with-dom=/usr/local" );

$three = $root->new_child("question", "" );
$three->setattr("number", "7" );
$three->new_child("text", "7. How to use DOM XML function ?" );
$three->new_child("answer", "Read this document source for
a simple example." );

//輸出到Browser
print("<pre>".htmlspecialchars($doc->dumpmem() )."</pre>" );

// write to file
//寫(xiě)回到文件
$fp = fopen("test_dom.xml", "w " );
fwrite($fp, $doc->dumpmem(), strlen($doc->dumpmem() ));
fclose($fp);

// ------------------------------------------------------
//現(xiàn)在使用xpath從XML文檔中得到內(nèi)容

$doc = xmldoc(join("", file("test_dom.xml")) );
$ctx = xpath_new_context($doc );

共2頁(yè)上一頁(yè)12下一頁(yè)
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 津市市| 永济市| 淮南市| 汕头市| 乌鲁木齐县| 新宁县| 台山市| 麻城市| 闻喜县| 东乌| 辰溪县| 新宾| 灌南县| 恩施市| 清水县| 麻阳| 富宁县| 浦城县| 织金县| 平舆县| 甘孜县| 中阳县| 凉城县| 乌鲁木齐县| 江永县| 渭源县| 宁陕县| 涡阳县| 青河县| 浦北县| 新宾| 二手房| 安吉县| 兴文县| 垣曲县| 梧州市| 土默特右旗| 齐齐哈尔市| 枞阳县| 望都县| 个旧市|