PHP技术操作XML文件

PHP技术操作XML文件

使用CSS引用

<?xml-stylesheettype="text/css" href="classess.css">

///

XML约束

Dtd: 文档类型定义

Schema

使用PHP技术操作XML文件

Php dom

php结合xpath 操作XML

SimpleXML

DOM说明

Dom(document object model)文档-对象-模型,核心思想是把一个XML看成一个对象

例子1

<!Doctypehtml><html xmlns=http://www.w3.org/1999/xhtml>

<head>

<metahttp-equiv=Content-Type content="text/html;charset=utf-8">

<metahttp-equiv=X-UA-Compatible content=IE=EmulateIE7>

<title>XML</title>

</head>

<?php

$xmldoc=newDoMDocument();

$xmldoc->load("info.xml");

var_dump($xmldoc);

$stus=$xmldoc->getElementsByTagName("theme");

echo"共有".$stus->length;

$stu1=$stus->item(0);

echogetNodeVal($stu1,"name");

functiongetNodeVal($MyNode,$tagName){

return$MyNode->getElementsByTagName($tagName)->item(0)->nodeValue;

}

?>

</html>

例子2

<!Doctypehtml><html xmlns=http://www.w3.org/1999/xhtml>

<head>

<metahttp-equiv=Content-Type content="text/html;charset=utf-8">

<metahttp-equiv=X-UA-Compatible content=IE=EmulateIE7>

<title>XML</title>

</head>

<?php

$xmldoc=newDoMDocument();

$xmldoc->load("info.xml");

//获取所有Theme

$stus=$xmldoc->getElementsByTagName("t1");

for($i=0;$i<$stus->length;$i++){

$stu=$stus->item($i);

echogetNodeVal($stu,"name")."---".getNodeVal($stu,"id")."<br/>";

}

functiongetNodeVal($MyNode,$tagName){

return$MyNode->getElementsByTagName($tagName)->item(0)->nodeValue;

}

?>

</html>

XML文档:

<?xmlversion="1.0" encoding="utf-8" ?>

<theme>

<t1>

<name>夜火情迷</name>

<id>b2b_yhqm</id>

<version>分销王</version>

<info></info>

<author>ShopEx</author>

<site>http://www.shopex.cn</site>

<update_url></update_url>

<borders>

<set key="默认"tpl="borders/border1.html" />

<set key="左边短"tpl="borders/border2.html" />

<set key="滑动门"tpl="borders/border3.html" />

<set key="右边无图商品列表"tpl="borders/border4.html" />

<set key="底部文章"tpl="borders/border5.html" />

<set key="备用"tpl="borders/border6.html" />

</borders>

<views></views>

<config></config>

</t1>

<t1>

<name>夜火情迷222</name>

<id>b2b_yhqm2222</id>

<version>分销王</version>

<info></info>

<author>ShopEx</author>

<site>http://www.shopex.cn</site>

<update_url></update_url>

<borders>

<set key="默认"tpl="borders/border1.html" />

<set key="左边短"tpl="borders/border2.html" />

<set key="滑动门"tpl="borders/border3.html" />

<set key="右边无图商品列表"tpl="borders/border4.html" />

<set key="底部文章"tpl="borders/border5.html" />

<set key="备用"tpl="borders/border6.html" />

</borders>

<views></views>

<config></config>

</t1>

</theme>