First off, let me just say please be patient with me... I barely know what I'm talking about here! I'm not even convinced this isn't a HTML or XML question rather than PHP but figure someone here can probably point me in the right direction...

I'm the administrator for an application for which the front end is built in PHP.

Its got an API which I can use to search the database behind it. It works by me firing off an XML file of my search criteria to a URL and then it the displays search results in XML.

For testing purposes I'm sending data to the API by manually filling in a webform although I will be using PHP to generate the XML send and POST it to the API eventually.

My problem however arrises with the data returned from the API and how I then use it on a website. My form looks like this;

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<form method="POST" action="http://applicationURL/parse.php" name="XML Form">
  <h2>XML Data</h2>
  <textarea cols="80" name="xml_doc" rows="20"></textarea>
    <br><br>
  <input type="submit" value="Submit" name="B1">
  <input type="reset" value="Reset" name="B2">
</form>

So I fill in the XML I want to send as search criteria (in this case it might have been <city>Random City</city>, click submit and my browser takes me to http://applicationURL/parse.php which is displaying XML that looks a little like this;

<?xml version="1.0" encoding="UTF-8" ?> 
<connector_ret>
<function name="search">
<row id="1">
  <col id="1">1266</col> 
  <col id="2">John</col> 
  <col id="3">Smith</col> 
  <col id="4">1 Any Road</col> 
  <col id="5">Some Area</col> 
  <col id="6">Random City</col> 
</row>
<row id="2">
  <col id="1">1364</col> 
  <col id="2">Mary</col> 
  <col id="3">Jane</col> 
  <col id="4">2 Another Street</col> 
  <col id="5">Town Centre</col> 
  <col id="6">Random City</col> 
</row>
</function>
</connector_ret>

Obviously I don't want my end user to be dumped on a page full of XML... how do I get it so that clicking submit will take me to http://www.applicationURL/searchresults.php for example and have the XML data from parse.php used on the page but formatted nicely?

    Greetings,
    Well, actually there are 2 main methods to format the XML content as you want.

    1. use XSLT
    2. Use the XML Parser to format it

    given your problem I think the best method is to use XSLT where you can format and style
    your XML content as you want.

    XSLT stands for EXtensible Stylesheet Language. Its mainly used to style and format XML content.
    please reffer to the following tutorials to learn about XSLT

    1. http://www.w3schools.com/xsl/
    2. http://www.topxml.com/xsl/tutorials/intro/default.asp

    Along with XSLT you may need to understand XPATH as well, the above tutorials provide step-by-step
    information to learn both these powerfull tools.

    the other way is to format you XML is to write code in your paser to format it. but i personally
    think XSLT provides a much better and powerfull way of formating and styling XML content.

    Best Regards
    Power Strider.

      5 days later

      Great stuff, thats for the pokes in the right direction!

      Hard to know what to read up on when you don't know what it is to read up on 🙂

        Write a Reply...