Forgot username/password? Don't have an account?
Login with Facebook
Home » Courses » 02Hero XML » Loading XML in PHP

Loading XML in PHP

So far, we have seen examples of how applications on the client side in web-interactions load XML data that is rendered to them as the content format. We'll now take a look at PHP, a specialized server-side language that makes XML content available to client applications such as HTML browsers, which then render this information as text in the browser window using special languages like Javascript. We'll start with a very simple example, using samples of XML information as well as a PHP script to load this document onto the browser application:

<?

$xmlString = "<canine>who let the dogs out?</canine>";

echo $xmlString;

?>

When this information is fed to the browser, it displays the output "Who Let the Dogs out?" correctly. It displayed data because the root element has no nested elements inside of it. If we store an XML document instead that consists of nested elements, it doesn't make sense to display the contents of the root element on the browser. It's not a simple string any more. So it simply displays a blank page, with NO content.

<?

$xmlString = "<canine>

<question>Who Let the dogs out?</question>

<answer>It's a dog's life!</answer>

</canine>"

echo $xmlString;

?>

In the next session we shall see what kind of PHP code needs to be written in order to parse any XML document and then give it to the client software (browser) so that only the content is correctly displayed. We can see the division of responsibilities between technologies and languages, all centered around content management. On the server side is PHP, and on the client side (mainly browsers,) it is Javascript. XML is the common glue that binds these technologies together, and provides a extensible and flexible framework for content management.

Got A Question?

'I love being Prime'

Have a question but don't want to ask it publicly? If you are a prime member just ask right here and we will get back to you within 48 hours. Not prime yet? no worries you can ask publicly below.

Act now while we have available seating

Our on line school is private, affordable and interactive with trainer support.
Act now save your seat before someone else takes yours.
Act now