Web Analytics Made Easy -
StatCounter Help me better understand XML - CodingForum

Announcement

Collapse
No announcement yet.

Help me better understand XML

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help me better understand XML

    I created a xml file called text.xml
    I created a xsl file called text.xsl

    I open the browser localhost/text.xml and everything is fine.

    My question is, I want to use php to retrieve my data from mysql server. then put the data into xml file. so, I have to generage a xml file with the data I just retrieved. What if there is 10 users visiting my site. do I have to produce 10 xml files?

    I know there is a better way to do that, I just don't know how.
    Last edited by weronpc; Mar 7, 2004, 09:55 PM.

  • #2
    I don't know much about PHP/XML, but I do know about PHP/HTML, and I'm assuming it's the same idea.

    Your XML file will actually be a PHP file, in that you will have PHP code embedded in your XML code. For example, if you need some database stuff for some following bit of XML code, you'd write the appropriate PHP code just before to get all the data together and use PHP echo statements to put your database data into the XML tags.

    xml_file.php:
    PHP Code:
    <xml>
     <?php
      $db 
    mysql_connect(...);
      
    mysql_select_db(...);

      
    $result mysql_query("select some_data from some_table");
      while(
    $row mysql_fetch_row($result)) {
     
    ?>

     <some_data>
      <?php echo $row[0]; ?>
     </some_data>

     <?php
      
    }//while
     
    ?>
    </xml>
    Does that sort of clear it up for you?

    If anyone else has additional comments, I'm sure they will post them to help you out.

    Sadiq.

    Comment


    • #3
      do I have to produce 10 xml files?
      PHP Code:
      you can either do a simple cache of the XML file ..

      <?
      header
      'content-type:text/xml' ) ;
      if(
      file_exists('blah.xml')){
          
      readfile('blah.xml');
      }else{
          
      //generate output from DB and save as blah.xml
      }
      ?>

      then whenever the data in the database changes ,
      delete blah.xml forcing a rewrite on the next page view...

      OR (and personally I think the above is preferable ?)

      <?
      header
      'content-type:text/xml' ) ;
      //build and output data
      ?>
      resistance is...

      MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

      Comment


      • #4
        To: Firepages
        }else{

        //generate output from DB and save as blah.xml

        }
        Do you think this will be fast? if I want search data, it will search in a text file.

        To: Sad69
        Your solution to me looks like only good for one user, what if 50 users visiting the site doing different queries? do I produce 50 xml files?

        Comment


        • #5
          heh, I guess I don't know enough about xml... so I'm sorry I can't answer that.

          But in my mind I still think you only need the one file. But leave me outt a this one, I shouldn't have butted in!

          Sadiq.

          Comment


          • #6
            searching an XML file when you have a database available seems pointless to me unless you want to search the XML file clientside ,
            regardless you still end up with a blah.xml to work with.

            so you could alter to...

            PHP Code:
            assuming $var && $var1 are search parameters or identifiers
            <?
            $requested 
            "cache.$var.$var1.xml";
            if(!
            file_exists($requested)){
                
            //grab your content from the DB
                //build your xml file
                
            $xmlfile ='<'.'?xml';  $xml .='/*etc*/';
                
            //etc .. & save it
                
            $fp=fopen($requested,'w');
                
            fputs($fp,$xml);
                
            fclose($fp);
            }
            //output
            header'content-type:text/xml' ) ;
            readfile($requested);
            ?>
            and yes you may end up with a cache of several XML files [perhaps named to suit the queryparameters ... cache.$var.$var1.xml where $var & $var1 are search parmeters] but there is nothing you can do about that , at least they only get created once the first time someone does that particular query (and again whenever the database content changes)
            resistance is...

            MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

            Comment

            Working...
            X