PHP xml_parse () फ़ंक्शन
❮ पीएचपी एक्सएमएल पार्सर संदर्भ
उदाहरण
XML पार्सर बनाएं और XML दस्तावेज़ को पार्स करें ( note.xml ):
<?php
// Create an XML parser
$parser=xml_parser_create();
function char($parser,$data) {
echo $data;
}
xml_set_character_data_handler($parser,"char");
$fp=fopen("note.xml","r");
while ($data=fread($fp,4096)) {
// Parse XML data
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)));
}
xml_parser_free($parser);
fclose($fp);
?>
परिभाषा और उपयोग
Xml_parse() फ़ंक्शन किसी XML दस्तावेज़ को पार्स करता है।
युक्ति: XML पार्सर बनाने के लिए, xml_parser_create() फ़ंक्शन का उपयोग करें।
वाक्य - विन्यास
xml_parse(parser, data, end)
पैरामीटर मान
Parameter | Description |
---|---|
parser | Required. Specifies the XML parser to use |
data | Required. Specifies the data to parse |
end | Optional. If set to TRUE, the data in the data parameter is the last piece of data sent in this parse. Note: Entity errors are reported at the end of the parse - and will only show if the end parameter is TRUE |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | सफलता पर सच। विफलता पर FALSE |
---|---|
पीएचपी संस्करण: | 4.0+ |
और ज्यादा उदाहरण
उदाहरण
उसी XML फ़ाइल का उपयोग करना लेकिन XML डेटा को दूसरे तरीके से प्रदर्शित करना:
<?php
$parser=xml_parser_create();
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 stop($parser,$element_name) {
echo "<br>";
}
function char($parser,$data) {
echo $data;
}
xml_set_element_handler($parser,"start","stop");
xml_set_character_data_handler($parser,"char");
$fp=fopen("note.xml","r");
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)));
}
xml_parser_free($parser);
fclose($fp);
?>
❮ पीएचपी एक्सएमएल पार्सर संदर्भ