XML CREATE IN PHP

Xml In Php
Xml In Php



Introduction to XML

Extensible Markup Language

What is XML

•XML stands for eXtensibleMarkup Language.
•A markup language is used to provide information about a document.
•Tags are added to the document to provide the extra information.
•HTML tags tell a browser how to display the document.
•XML tags give a reader some idea what some of the data means.

What is XML Used For?

•XML documents are used to transfer data from one place to another often over the Internet.
•XML subsets are designed for particular applications.
•It is used to send breaking news bulletins from one web site to another.
•A number of fields have their own subsets. These include chemistry, mathematics, and books publishing.
•Most of these subsets are registered with the W3Consortium and are available for anyone’s use

Advantages of XML

•XML is text (Unicode) based.
»Takes up less space.
»Can be transmitted efficiently.
•One XML document can be displayed differently in different media.
»Html, video, CD, DVD,
»You only have to change the XML document in order to change all the rest.
•XML documents can be modularized. Parts can be reused.

Example of an XML Document



<?xml version=“1.0”/>

<address>

<name>Alice Lee</name>

<email>alee@aol.com</email>

<phone>212-346-1234</phone>

<birthday>1985-03-22</birthday>

</address>

XML Rules

•Tags are enclosed in angle brackets.
•Tags come in pairs with start-tags and end-tags.
•Tags must be properly nested.
… is not allowed.
… is.
•Tags that do not have end-tags must be terminated by a ‘/’.

is an html example.

More XML Rules

•Tags are case sensitive.

is not the same as

•XML in any combination of cases is not allowed as part of a tag.
•Tags may not contain ‘<‘ or ‘&’.
•Tags follow Java naming conventions, except that a single colon and other characters are allowed. They must begin with a letter and may not contain white space.
•Documents must have a single root tag that begins the document.

PHP SimpleXML – Read Data From String

$xmldata=”<?xml version=’1.0′ encoding=’UTF-8′?>
<note>
<to>john</to>
<from>amritsar</from>
<heading>Admition</heading>
<body>Check Your List!</body>
</note>”;

 

Example:

<?php
$xmldata=”<?xml version=’1.0′ encoding=’UTF-8′?>
<note>
<to>john</to>
<from>amritsar</from>
<heading>Admition</heading>
<body>Check Your List!</body>
</note>”;
$xml=simplexml_load_string($xmldata) or die(“Error: Cannot create object”);
print_r($xml);
?>

The output of the code above will be:

SimpleXMLElement Object ( [to] => john [from] => Amritsar [heading] => Admition[body] => Check Your List! )

Get Data From Xml File



<?php
$xml=simplexml_load_file(“myfile.xml”) or die(“Error: Cannot create object”);
foreach($xml->Student() as $books) {
echo $book->Title . “, “;
echo $book->Author . “, “;
echo $book->Year . “, “;
echo $book->Price . “<br>”;
}
?>

One Comment

  1. hermes belt said:

    I have to point out my gratitude for your generosity in support of those who really want help with this subject. Your very own commitment to getting the message along ended up being exceedingly important and have constantly permitted many people just like me to attain their ambitions. Your personal warm and friendly key points implies a great deal a person like me and far more to my peers. Thanks a lot; from everyone of us.

    January 3, 2018
    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code