Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML with PHP

Status
Not open for further replies.

blinkbob123

Technical User
Feb 3, 2005
4
GB
Hi, i've just started learning xml. I've been using php (output in html) with a mysql database for years but thought i'd find out what the big deal was with xml. I read the xml tutorial over at w3schools.com but there's a couple things I can't understand.

Say I wish to do a search from the mysql database and put the results within tags in xml format. I try putting:
<?php

echo '
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
';

?>

in a file called test.php but although the source is correct (as you would expect) in your browser it doesn't display in the fancy way it would if the file extension was .xml (eg So how could I query the database using xml files to display it in the .xml format.

Also I've probably missed something on the tutorials but as I see it xml files use a style sheet (xslt file) which is calls and that parses the information in the xml file to display it in html. Say I wish to display the results of this page:


on my website in html. Then how would I go about doing this in php.

I'd appreciate if someone could help and I apologies if it may seem really simple but I've just go so used to mysql - php - html.
 
So how could I query the database using xml files to display it in the .xml format.
I'm not a html expert, but you'd probably need to tell the browser what the mime type is of your data.

which is calls and that parses the information in the xml file to display it in html.
In this case, don't think of the xslt file as a stylesheet, but instead thing of it as a set of transformation rules. You'd put the skeleton of your html file in the .xslt file, and everywhere you expect to show some data from the xml, you would insert an XPath query using xsl:value-of
Code:
<html>
<head>
head stuff here
</head>
<body>
Hello, <xsl:value-of select="//firstName"/>
</body>
</html>
Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top