婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > php 使用expat方式解析xml文件操作示例

php 使用expat方式解析xml文件操作示例

熱門標簽:欣思維地圖標注 高德地圖標注位置怎么標注 江西電銷機器人收費 電銷機器人沒有效果怎么樣 天潤融通外呼系統好嗎 杭州語音電銷機器人 江門回撥外呼系統 高德地圖標注店鋪收費嗎 泊頭在哪里辦理400電話

本文實例講述了php 使用expat方式解析xml文件操作。分享給大家供大家參考,具體如下:

test.xml:

?xml version="1.0" encoding="UTF-8"?>
notes>
 note>
 to>George/to>
 from>John/from>
 heading>Reminder/heading>
 body>Don't forget the meeting!/body>
 /note>
 note>
 to>George2/to>
 from>John2/from>
 heading>Reminder2/heading>
 body>Don't forget the meeting!2/body>
 /note>
 instances>
 instance st="192.168.234.121" />
 instance st="192.168.234.28" />
 /instances>
/notes>

PHP文件:

?php
// Initialize the XML parser
$parser = xml_parser_create();
// Function to use at the start of an element
function start($parser, $element_name, $element_attrs)
{
  switch ($element_name) {
    case "NOTE":
      echo "-- Note --br />";
      break;
    case "TO":
      echo "To: ";
      break;
    case "FROM":
      echo "From: ";
      break;
    case "HEADING":
      echo "Heading: ";
      break;
    case "BODY":
      echo "Message: ";
  }
}
// Function to use at the end of an element
function stop($parser, $element_name)
{
  echo "br />";
}
// Function to use when finding character data
function char($parser, $data)
{
  echo $data;
}
// Specify element handler
xml_set_element_handler($parser, "start", "stop");
// Specify data handler
xml_set_character_data_handler($parser, "char");
// Open XML file
// $fp = fopen("test.xml", "r");
// Read data
// while ($data = fread($fp, 10)) {
// xml_parse($parser, $data, feof($fp)) or die(sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)));
// }
// fclose($fp);
$data = file_get_contents("test.xml");
xml_parse($parser, $data) or die(sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)));
// Free the XML parser
xml_parser_free($parser);
?>

運行結果:

-- Note --
To: George
From: John
Heading: Reminder
Message: Don't forget the meeting!

-- Note --
To: George2
From: John2
Heading: Reminder2
Message: Don't forget the meeting!2

PS:這里再為大家提供幾款關于xml操作的在線工具供大家參考使用:

在線XML/JSON互相轉換工具:
http://tools.jb51.net/code/xmljson

在線格式化XML/在線壓縮XML
http://tools.jb51.net/code/xmlformat

XML在線壓縮/格式化工具:
http://tools.jb51.net/code/xml_format_compress

XML代碼在線格式化美化工具:
http://tools.jb51.net/code/xmlcodeformat

更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP針對XML文件操作技巧總結》、《PHP數組(Array)操作技巧大全》、《php字符串(string)用法總結》、《php面向對象程序設計入門教程》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》

希望本文所述對大家PHP程序設計有所幫助。

您可能感興趣的文章:
  • linux下php安裝xml擴展的詳細步驟
  • php實現的數組轉xml案例分析
  • PHP讀取XML文件的方法實例總結【DOMDocument及simplexml方法】
  • PHP創建XML的方法示例【基于DOMDocument類及SimpleXMLElement類】
  • 使用php操作xml教程

標簽:大同 江門 雙鴨山 駐馬店 內江 深圳 石嘴山 平涼

巨人網絡通訊聲明:本文標題《php 使用expat方式解析xml文件操作示例》,本文關鍵詞  php,使用,expat,方式,解析,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《php 使用expat方式解析xml文件操作示例》相關的同類信息!
  • 本頁收集關于php 使用expat方式解析xml文件操作示例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 和平区| 茌平县| 丰城市| 保康县| 万源市| 江山市| 鸡泽县| 历史| 中牟县| 西充县| 七台河市| 曲阜市| 侯马市| 沁源县| 中阳县| 泾川县| 昆明市| 蓝山县| 东光县| 桂平市| 原阳县| 哈巴河县| 广饶县| 德保县| 绥江县| 镇康县| 沙湾县| 兴隆县| 房产| 凭祥市| 行唐县| 镇远县| 汾西县| 封丘县| 精河县| 琼结县| 元朗区| 油尖旺区| 沈阳市| 蒙城县| 阳谷县|