***This thread was made because many people were asking or saying they needed help or wanted an XML Web page


XML - Extensible Markup Language
Use - Allows users to define there own customized Markup Languages, and allows for a much neater use then HTML

Description: XML Is a markup language that allows users to define there own tags and classes in a document. All XML Files require a main body class which the user is allowed to make up. When displaying this, you do not need to define the actual body class though. XML Can be used as an alternative to HTML As HTML gets very messy at times.
__________________

How To;

- Use it: XML is Defined in PHP. Although there are programs that can run it, PHP is still most oftentimes used to display it.

- Run it: Running an XML File requires two things; A XML File, and a PHP Script. First you must create a XML File and give it values, and then call it in php and display it using an echo function.

- Program it: XML is Programmed by the user himself! XML Can have as many tags and classes as the user likes, as long as it has a main body tag. Examples are posted below.
_______________________

Examples & Tutorials:
Format: Name (Type - Difficulty) Credits To

Spoiler for Creating (Tutorial - Easy) By: Rage-Quit:

XML is a Programming language that most people do not use because of the time it takes to create and actually run it, when it actually does not take much time at all! All you need is a simple PHP Script and a XML Document!

Index:

Prologue - XML Extensions
Part 1 - Naming your XML File
Part 2 - Body Tags
Part 3 - Classes
Part 4 - Neatness

____

Prologue - XML Extensions

XML Files should always end with the extension '.xml', which means 'Extensive Markup Language'

____

Part 1 - Naming your XML File

As many of you know, your files should be named to along with what your doing. For example, a voting page should not be named donating. This is just for organizing your files and being able to find them easily and making other users not confused. When naming your XML File, you can either name it 'index.xml' or 'xml.xml'. It does not matter what you name it, but you should name it so it goes with your files so you do not get confused and so you can properly call it without having to look back to remember what it was called. 'xml.xml' is usually a good name to name it, as it is short and actually fits the xml format!

____

Part 2 - Body Tags

As stated many times above, an XML Document always requires a main body tag. Although this does not need to be defined in your PHP Document, it is still necessary for your XML Document to function and run properly (lol?). An example of a main body tag would be '<xml></xml>' as it goes with the XML File language, fits the file, and is short. You can do whatever you want, but it is recommended you do something that fits the file as it makes it look more neat.

____

Part 3 - Classes

In XML, You need classes besides a main body tag. Some class examples are listed below;

Code:
<xml>

   <info>

      <name>
      </name>

   </info>

</xml>
As you can see, there are two classes ; A 'info' class, and then a 'name' class inside of that. The name class is in the info class because your name is considered information. If you were to add something like '<chair></chair>', it wouldn't make much sense because it isn't information.

____

Part 4 - Neatness

XML Should always be neat. As stated above, you'll see that your tags should always fit your classes inside of them, and your xml file should go along with what your doing. If not, it makes the code confusing and boring (even know it already is boring), and makes it hard to understand



Spoiler for Running XML (Tutorial - Easy) By: Rage-Quit:

In this tutorial, you will be running your XML File in php and displaying the information on a web page. Please note that this tutorial will be shorter then the usual tutorials!

Index:

Part 1 - Calling an XML File in PHP
Part 2 - Displaying/Defining Simple Text

____

Part 1 - Calling an XML File in PHP

Calling a XML File in PHP is actually very simple. From the Release of PHP 5.2.14, PHP Has actually allowed you to use a function that is built in to PHP to call a XML File from your directory and run it, but does not allow you to actually show the text, which we will be defining later on.

To call a XML File, you will be using the php function called 'simplexml_load_file'.

Example:

Code:
<?php

$xml = simplexml_load_file('xml.xml');

?>
Doing this will actually call the XML File so you can later define it.

____

Part 2 - Displaying/Defining Simple Text

To display XML Text from a XML file, you must first need a XML File that has a main body tag, classes with text, and the php function that calls your xml file in your php code.

First, you will need to make a XML File. Luckily, I already have one from previous work and will display it here:

Name: xml.xml
Code:
<xml>

	<dev>
	
		<name>Name: Logan</name>
		<desc>Description: Description Here</desc>
		<msn>Msn: [email protected]</msn>
	
	</dev>
	
	<dev>
	
		<name>Name: Open</name>
		<desc>Description: Empty</desc>
		<msn>Msn: Empty</msn>
	
	</dev>	
	
	<dev>
	
		<name>Name: Open</name>
		<desc>Description: Empty</desc>
		<msn>Msn: Empty</msn>
	
	</dev>

</xml>
This is an XML File with a main body tag named '<xml>', and a class named '<dev>', with 3 sub tags named '<name>', '<desc>', and '<msn>'.

Next, you will need to call the function in PHP by writing;

Code:
<?php

$xml = simplexml_load_file('xml.xml');

?>
Now is the tricky part. We will actually be displaying text from the file, so follow my code;

Code:
<?php
	
	$xml = simplexml_load_file('index.xml');
	
	echo $xml->dev[1]->name.'<br>'.$xml->dev[1]->msn.'<br>'.$xml->dev[1]->desc;
	echo $xml->dev[2]->name.'<br>'.$xml->dev[2]->msn.'<br>'.$xml->dev[2]->desc;
	echo $xml->dev[3]->name.'<br>'.$xml->dev[3]->msn.'<br>'.$xml->dev[3]->desc;
	
?>
Now, what we are doing here is simple. First, we are calling our XML file named 'xml.xml', and then we are echoing the text from the file. The question is, how just exactly are we displaying this text? Well, first off, you are calling your XML file, which I already said. Then, you need to simple write a '->'. Next, you are searching for the class named 'dev' (because we do not need to define the main body tag as stated above). The problem is; what if there are multiple classes named 'dev'? No problem! XML Has a built in processor that sorts all of your classes in to certain rows. This means that if you have 3 'dev' classes, it sorts them in to 3 rows, and makes it so the first one is named row 1, and so on, so on. Next, we need to actually select a row, so we do that by putting brackets ([]'s) and then putting the row we wish to select from in there. Now, you will be writing another '->' and then putting the tag you wish to select from in there. In my case, I only have one name tag in my code, so I do not need to select from a row to display it. Now, if you wish to continue on and write more code from that same class, you simply put a plain '.' (period, no '' marks) and then rewrite the code the exact same except with a different end tag. In my case, I wanted all of the code to start on a different line, so I simply just wrote '.'<br>'.' to symbolize ending a code and writing text, and then starting the code again, which works in this case. You can continue on writing out the code, just remember to select from different rows each time so you do not end up writing the same text!

NOTE: After displaying a class from a certain row, and then displaying another class from a certain row, you do not need to write out the row of the tag because you already wrote out the row for the class...

For example, you do not need to do:

Code:
$xml->info[1]->name[1];
Because you already selected the first row/class named info. If there is more then one tag named 'name', then you do need to do this though!


_________________________________

Want to submit your own tutorial or code? Simply fill out this format! :

Code:
Format: Name (Type - Difficulty) By: 
Code: