example of using xml parser in php: expat
2007-09-13 19:14
447 查看
PHP Resource
http://www.w3schools.com/php/default.asp<?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,4096))
{
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)));
}
//Free the XML parser
xml_parser_free($parser);
?>
相关文章推荐
- Example Code of Using XML Parser in Symbian OS
- Step By Step guide to Read XML file in Java Using SAX Parser Example
- example of using ajax in VisualForce page
- Tree in Combo Box example code (using HTTPService and XML)
- An Example Of Validating Text Item In Oracle Forms Using When-Validate-Item Trigger
- PHP: Send the Authorization token in a header instead of on the querystring and 读取 XML
- A simple Example of using Video Textures in Managed DirectX (C#)
- Example of Using Google Maps Service and GPS in Android
- An example of a trading strategy coded using Quantmod Package in R
- example of using ActionFunction in Salesforce
- [PHP] To display some attribute of the node in the XML document.
- Using DocumentFormat.OpenXml to generate a new excel file in terms of temp excel file
- Real time example of using BADI in SAP
- JDOM Example : Reading and Parsing XML with SAX parser in Java
- A coroutine example: Streaming XML parsing using xml_parser
- An Example of Pre-Query and Post-Query Triggers in Oracle Forms With Using Display_Item to Highlight Dynamically
- 解析XML时,org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 449: not well-forme
- Expat XML parser
- org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: unknown encoding
- Serialize and deserialize objects as Xml using generic types in C# 2.0