Using PHP we can read and execute the XML files. We can use the XML files to store the information as we do with the database.
PHP provides all the methods needed for the reading, writing and executing the XML files.Before that we need to know the XML.
An XML document comprises elements, attributes, processing instructions, comments, and entities
Element: Text delimited by an opening and a closing tag. A tag is a name enclosed within angle brackets.
Attribute: A piece of qualifying information for an element. An attribute consists of a name, an equals sign, and an attribute value delimited by either single-quotes or double-quotes.
Processing instruction: The software that is reading an XML document is referred to as a processor. A processing instruction is additional information embedded in the document to inform the processor and possibly change its behaviour.
Comment: An XML comment begins with the characters: less-than, exclamation mark, minus, minus; and ends with the characters: minus, minus, greater-than. Any text within a comment is intended for a human reader and is ignored by the processor.
Entity: An entity is a compact form that represents other text. Entities are used to specify problematic characters and to include slabs of text defined elsewhere. An entity reference consists of an ampersand, a name, and a semi-colon.
A simple XML file we will
<?xml version="1.0" encoding="utf-8" ?>
<people title="students"
>
<name1> student name 1
</name1>
<name2> student name 2
</name2>
<name3> student name 3
</name3>
</people>
Steps for reading this simple XML file is:
$xml = simplexml_load_file('names.xml');
This step will load the xml files. It Interprets an XML file into an object.Returns an object of class SimpleXMLElement with properties containing the data held within the XML document. On errors, it will return FALSE.
To read the data from the simple xml file we write code as
$xml = simplexml_load_file('names.xml');
print $xml->name1;
# Seperates outputs (easier to read & understand)
print "
# You call an attribute just like you would with an array: $array['arrayname/number']
print $xml['title'];
outputs : student name 1 ## Title output is -- name1
For an XML with multiple Items we write code as
<?xml version="1.0" encoding="utf-8" ?>
<student title="students">
<item id="1">
<name>
<first>ram</first>
<last>test</last>
</name>
<ageᡢ</age>
</item>
<item id="2">
<name>
<first>prince</first>
<last>kumar</last>
</name>
<ageᡃ </item>
<item id="3">
<name>
<first>raju</first>
<last>ramesh</last>
</name>
<ageᡍ</age>
</item>
</student>
# Load the test.xml file
$xml = simplexml_load_file('test.xml');
# Start a foreach loop. Translation: for every
# now the $item can display all the elements inside the
foreach($xml->item as $item) {
# These three print's will display the attribute of the
# and then the age. The and are for spacing out the results
print "ID: " . $item['id'] . "
";
print "Name: " . $item->name->first . " " . $item->name->last . "";
print "Age: " . $item->age . "";
}
If we want to provide the conditions when executing the XML files then the code will be
# Load the test.xml file
$xml = simplexml_load_file('test.xml');
# Start a foreach loop. Translation: for every
# now the $item can display all the elements inside the
foreach($xml->item as $item) {
$age = $item->age;
if ($age >= 10) {
if ($age <= 21) {
# These three print's will display the attribute of the
# and then the age. The and are for spacing out the results
print "ID: " . $item['id'] . "
";
print "Name: " . $item->name->first . " " . $item->name->last . "";
print "Age: " . $item->age . "";
}
}
}


2 comments:
成人視訊,色情影片,台灣無限貼圖,美女交友,成人,6k聊天室,ut聊天室,免費視訊,免費視訊,台灣美女貼圖區,免費交友,正妹視訊,成人視訊,正妹星球,情色視訊,dudu 嘟嘟貼圖區,18成人,美女交友,85cc成人片,成人影片,免費視訊,f 罩杯美女圖片,美女交友,成人文學,aqaq 視訊聊天室,av貼圖,美女交友,ut聊天室,080視訊聊天室,視訊聊天室,ut男同志聊天室,免費交友,免費視訊聊天,成人動畫,人之初貼圖區,免費視訊,同志聊天室,ut聊天室,成人視訊,交友聊天室,尼克成人,成人動漫,交友戀愛小站,免費交友
情色視訊777成人區聊天室成人視訊聊天成人視訊Uthome後宮電影電影院免費視訊辣妹正宗自拍美女aooyy韓國小遊戲視訊聊台中酒店S援交一葉情貼影片區小魔女免費影片sexygirl免費線上影片bt論壇sex520免費影片情境坊歡愉用品18成人日本avdvd介紹免費觀賞
Post a Comment