SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating backends (xml) with PHP

    Greetings

    I'm about to attempt the creation of xml backends with php with data taken from a mysql database. I'm totally new to xml, but i'm familiar with basic concepts like the ability to make up my own tags and attribute names. Of cause, the strict end tags.

    Could anyone point me in the right direction?

    At this time, i'm thinking about:
    - How php should write to the file and how can it be formatted properly? like indents?
    - How i should assign the various tags for my xml backend


    I would be thinking about (but not now):
    - How php can be used to parse a xml backend. something like xml_parse() from what i read at php.net?


    Many thanks!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  2. #2
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Indentation in XML is not important, whitespace between tags is ignored for most things.

    The tag names are up to you, it's worth reading up a LOT on XML before designing your scheme though as you'll really want to get it right.

    As far as parsing goes you're goign to have to learn about Expat and DOM based parsing and figure out which one is right for you. These are pretty tricky subjects, but there are some excellent tutorials on www.devshed.com in the PHP section.

  3. #3
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Thanks shunk for responding. Wow. seems to be that I have some work to do. Thanks!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  4. #4
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    i have been doing a lot of digging in css and most of that in w3c.
    stylesheets and xml may offer some assistance. But most of that information is on the dtd.

    There is a ref to an article at www.devshed.com/client_side/xml that i cannot seem to open. the article is titled "using php with xml" parts 1 and 2 with the author icarus.

    i really hope this can be of some use.

  5. #5
    SitePoint Zealot pnathan's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lynlimz

    I am kinda doing the same thing as you, and it has taken me a while but I am finally making progress.

    I am building a XML based CMS, the user enters the data in a webform, this gets turned into an xml file which is formatted by an XSLT file and then parsed by a PHP file and outputted to the browser.

    If you are looking to do something similar then let me know and I will post some code.
    I have two tickets to the Crows, sweet.

  6. #6
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by pnathan
    the user enters the data in a webform, this gets turned into an xml file
    Please post the webform to xml code.
    My version is very cumbersome and I need some new fresh ideas.
    I'm experiencing code block.



    Cheers.

  7. #7
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm considering doing a site this way, but I'm concerened about the extra overhead of having to do the XSL transformations. Is this a legitimate concern, or is the slow-down negligible?

  8. #8
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by pnathan
    If you are looking to do something similar then let me know and I will post some code.
    Hi pnathan,

    Could you post the code please? That would certainly help. thanks!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  9. #9
    SitePoint Zealot pnathan's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, so you want the code, here goes.

    First the normal html webform:

    Code:
    <form method="post" action=trans_xml.php>
    		  <table width="800">
    		  <input type=hidden name="mode" value="1">
      		  	<tr>
    				<td width=120 class=SUBPAGE>Filename (For Admin eg: CapeNews9):</td>
    				<td width=600 class=SUBPAGE><input type="text" name="filename" size="50"></td>
    			</tr>
    		  	<tr>
    				<td width=120 class=SUBPAGE>Title of Newsletter</td>
    				<td width=600 class=SUBPAGE><input type="text" name="title" size="50"></td>
    			</tr>
    		  	<tr>
    				<td width=120 class=SUBPAGE valign=top>Intro Text</td>
    				<td width=600 class=SUBPAGE><textarea cols="40" rows="5" name="intro"></textarea></td>
    			</tr>
    			<tr>
    				<td colspan=2>&nbsp;</td>
    			</tr>
    		  	<tr>
    				<td width=120 class=SUBPAGE>Heading Section 1</td>
    				<td width=600 class=SUBPAGE><input type="text" name="heading1" size="50"></td>
    			</tr>
    			<tr>
    				<td width=120 class=SUBPAGE valign=top>Content Section 1</td>
    				<td width=600 class=SUBPAGE valign=top><textarea cols="60" rows="10" name="content1"></textarea></td>
    			</tr>
    			<tr>
    				<td width=120 class=SUBPAGE></td>
    				<td width=600 class=SUBPAGE align=right><input type="submit" value="Enter"></td>
    			</tr>
    		  </form>
    		  </table>
    Note that the action is the trans_xaml.php and that I can name the xml file from this form.

    Now the php code that creates the xml page. Before you do this, create a blank file xml in the same folder, I have called it "blank.xml". It is very important that precise syntax below is used.

    PHP Code:
    <?$xml_data='<?xml version="1.0"?>
    <newsletter>
    <header>
        <name>'
    .$title.'</name>    
        <intro>'
    .$intro.'</intro>    
        </header>
        <section>
            <heading>'
    .$heading1.'</heading>
            <content>'
    .$content1.'</content>
            <url>'
    .$URL1.'</url>        
        </section>
    </newsletter>'
    ;

    copy('blank.xml','blank2.xml');
    $new_name "$filename.xml";
    $fp=fopen("blank.xml","w");
    fputs($fp,$xml_data);
    fclose($fp);
    rename('blank.xml',$new_name);
    rename('blank2.xml','blank.xml');

    ?>
    Then I have a well formed xml page. Note that I am left with the same blank.xml file, this allows me to create more xml files etc...
    I have two tickets to the Crows, sweet.

  10. #10
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi pnathan, thanks for taking the time to post the code.

    Do you have the php code to retrieve data from an xml sheet like that?
    Just want to clarify.
    The tag names for the xml sheet can be of any name right?
    thanks
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  11. #11
    SitePoint Zealot pnathan's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lynlimz

    You can name the XML tags however you wont. What I am trying to explain is that you can control the name of the xml file you are creating. This is where it is done:
    PHP Code:
    $new_name "$filename.xml"
    Ok, I will post the XSL file and the PHP parser.
    Here is the XSL

    Code:
    <?xml version="1.0"?>
    
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:template match="/">
    
    	<html>
    	<head>
    	</head>
    	<body>
    	<table width="650">
    	<tr>
    		<td width="600" align="right" ><b><xsl:value-of select="newsletter/file/name" /></b></td>
    	</tr>
    	<tr>
    		<td width="600" align="left" ><xsl:value-of select="newsletter/header/intro" /></td>
    	</tr>
    	<tr>
    		<td width="600" height="10" align="left"></td>
    	</tr>	
    	<tr>
    		<td width="600" align="left"><xsl:value-of select="newsletter/section[1]/heading" /></td>
    	</tr>
    	<tr>
    		<td width="600" align="left"><a href="{newsletter/section[1]/url}" target="_new"><xsl:value-of select="newsletter/section/content" /></a></td>
    	</tr>
    	</table>
    	</body>
    	</html>
    
    </xsl:template>
    
    </xsl:stylesheet>
    Here is the PHP Parser:

    PHP Code:
    <?php

    // store XML and XSL content as variables
    $xmlstring join(''file('filename.xml'));
    $xslstring join(''file('filename.xsl'));

    // call the XSLT processor directly
    xslt_process($xslstring$xmlstring$result);

    // output the result
    echo $result;
    ?>
    Remeber, you need the Sablot extensions for this to work.
    I have two tickets to the Crows, sweet.

  12. #12
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by pnathan
    Remeber, you need the Sablot extensions for this to work.
    Hmm..how do i determine if I have the sablot extensions?
    Can i call the xml file from another server?

    Thanks!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  13. #13
    SitePoint Zealot pnathan's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This article will tell you all you need to know.
    I have two tickets to the Crows, sweet.

  14. #14
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow thanks!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  15. #15
    The short answer is yes... Herbster's Avatar
    Join Date
    Oct 2001
    Location
    Bay City, Oregon
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by edshuck
    hi

    i have been doing a lot of digging in css and most of that in w3c.
    stylesheets and xml may offer some assistance. But most of that information is on the dtd.

    There is a ref to an article at www.devshed.com/client_side/xml that i cannot seem to open. the article is titled "using php with xml" parts 1 and 2 with the author icarus.

    i really hope this can be of some use.
    Found this thread in a query.
    You may have already found it, but the article can be found here:
    http://www.devshed.com/Server_Side/X...HP1/page1.html


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •