|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
embedding xml file into a php page (newbie)
this is what i want to do:
i have a php-page let it be the following: <html> <body> ... ... <?php include ('xmlfile.xml'); ?> .. .. </body> </html> the page displayed in explorer is a blank page, but in the html source i can see exactly the code in my xml file If call in my browser http://localhost/folder/xmlfile.xml it is displayed correctly and it works good reagarding the expand and collapse functionalities (using a xsl file to transform it) I can immagine that it is a stupid problem, but i'm really new to xml (started today....EARLY in the morning!!!) in a fiew words: as i can display a xml file in explorer, can i embed the same file into a html page (or php page) without parsing and manipulating it?? the scope of my work is to have a left-menu in my page based on the xml file, i have prepared a div section where to embed the menu, i have formatted the xmlfile to display with folders plus&minus images and so on, and i have tested it alone.....but when i included it into my page i had that bad surprise....it didn't work ![]() please.... just telling me "yes you can do it" or "no it is impossible, you have to use a parser and display the content of the xml file by a php script" woud be appreciated. (but if you have some more hints they would be much more appreciated) thanks in advance Duccio |
|
#2
|
||||
|
||||
|
What happens when you just put the xml file inside the html file via copy and paste, only grab the root node and its content not the xml declaration.
![]()
__________________
Teflon - The Black <desc>Mark This Up</desc> |
|
#3
|
|||
|
|||
|
Sorry i've tried to do it, but i'm too newbie and i make some more mistakes i think... i'll post the sources to make it clearer to me....if you could loose some more time with me i'd be very glad..
this is the xml file i've found here in this forum....just to start with a working source... Code:
<?xml-stylesheet type="text/xsl" href="xml_tree.xsl"?> <menu icon1="images/home.gif" caption="Books & Publications"> <menuItem caption="Science Fiction"> <menuItem action="17" title="Worst Case Scenario" caption="Tanwani Anyangwe"></menuItem> <menuItem action="4" title="Jurasic Park" caption="Micheal Crichton"></menuItem> <menuItem action="3" title="Star Wars" caption="George Lucas"></menuItem> </menuItem> <menuItem caption="Cold War" opened="false" icon1="images/refresh.png"> <menuItem action="10" caption="The Forth Protocol"></menuItem> <menuItem action="3" caption="Fire Fox"></menuItem> <menuItem action="31" caption="United Artists"> <menuItem action="310" caption="Dr. No" /> <menuItem action="311" caption="From Russia with Love" /> <menuItem action="1" caption="Live & Let Die" /> <menuItem action="31" caption="Diamonds are Foreever" /> <menuItem action="31" caption="Never Say Never Again" /> <menuItem action="31" caption="For you eyes only" /> <menuItem caption="Eastern Block Fictions" icon1="images/closed.gif" icon2="images/open.gif"> <menuItem action="10" caption="The Forth Protocol"></menuItem> <menuItem action="3" caption="Fire Fox"></menuItem> <menuItem action="31" caption="James Bond (007)"> <menuItem action="310" caption="Dr. No" /> <menuItem action="311" caption="From Russia with Love" /> <menuItem action="1" caption="Live & Let Die" /> <menuItem action="31" caption="Diamonds are Foreever" /> <menuItem action="31" caption="Never Say Never Again" /> <menuItem action="31" caption="For you eyes only" /> </menuItem> <menuItem action="13" caption="Maya Durashka"></menuItem> </menuItem> </menuItem> <menuItem action="13" caption="Maya Durashka"></menuItem> </menuItem> <menuItem icon1="images/copy.small.png" caption="Western Herritage"> <menuItem action="10" title="Tom Sawyer" caption="Mark Twain"></menuItem> <menuItem action="70" title="Roots" caption="Alex Harley"></menuItem> </menuItem> <menuItem icon1="images/notepad.png" caption="African American Herritage"> <menuItem action="70" title="Roots" caption="Alex Harley"></menuItem> </menuItem> </menu> and this is the xsl file (xml_tree.xsl) used for transformations: Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- Author: Tanwani Anyangwe (tanwani@aspwebsolution.com) -->
<!-- Web Site: http://www.aspwebsolution.com -->
<!-- This template and many more are available free online at http://www.aspwebsolution.com -->
<xsl:output method="html" version="4.0" />
<xsl:template match="/">
<html>
<head>
<title>XML Tree</title>
<script language="javascript">
<![CDATA[
function toggle(id,closed,opened,pre){
var myChild = document.getElementById(id);
var myPIcon = document.getElementById("picon" + id);
var myIcon = document.getElementById("icon" + id);
if(myChild.style.display=="none"){
myChild.style.display="block";
myIcon.src=opened;
myPIcon.src="images/"+ pre + "minus.png";
}else{
myChild.style.display="none";
myIcon.src=closed;
myPIcon.src="images/"+ pre +"plus.png";
}
}
]]>
</script>
<style>
a:link{color:black;text-decoration:none;font-size:8pt;font-family:verdana;}
a:visited{color:black;text-decoration:none;font-size:8pt;font-family:verdana;}
a:hover{color:blue;text-decoration:underline;font-size:8pt;font-family:verdana;}
</style>
</head>
</html>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="menu">
<div>
<img src="images/home.gif" border="0" />
<xsl:text>*</xsl:text>
<a href="#">
<xsl:value-of select="@caption" />
</a>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="menuItem">
<xsl:variable name="hasChild">
<xsl:if test="menuItem">true</xsl:if>
</xsl:variable>
<xsl:variable name="prefix">
<xsl:choose>
<xsl:when test="position()=last()">
<xsl:text>L</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>T</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td>
<xsl:choose>
<xsl:when test="$hasChild='true'">
<xsl:variable name="myId" select="generate-id()" />
<xsl:variable name="icon1">
<xsl:value-of select="'images/folder-closed.gif'" />
</xsl:variable>
<xsl:variable name="icon2">
<xsl:value-of select="'images/folder-open.gif'" />
</xsl:variable>
<xsl:variable name="style">
<xsl:if test="position() < last()">
<xsl:text>border-left:1px dotted gainsboro;</xsl:text>
</xsl:if>
</xsl:variable>
<div onclick="toggle('{$myId}','{$icon1}','{$icon2}','{$prefix}')">
<img src="images/{$prefix}plus.png" border="0" align="absMiddle" id="picon{$myId}" />
<img src="{$icon1}" border="0" align="absMiddle" id="icon{$myId}" />
<xsl:text>*</xsl:text>
<a href="#">
<xsl:value-of select="@caption" />
</a>
</div>
<div style="padding-left:8px;">
<table border="0" style="{$style}" cellspacing="0" cellpadding="0">
<tr>
<td>
<span id="{$myId}" style="display:none;padding-left:10px;">
<xsl:apply-templates />
</span>
</td>
</tr>
</table>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="doc">
<xsl:choose>
<xsl:when test="position()=last()">
<xsl:text>images/l.png</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>images/t.png</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<div >
<img src="images/{$prefix}.png" border="0" align="absMiddle" />
<img src="images/file.gif" border="0" align="absMiddle" />
<xsl:text>*</xsl:text>
<a href="#">
<xsl:value-of select="@caption" />
</a>
</div>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
if i display a page made like so: Code:
<html> <head> </head> <body> <?xml-stylesheet type="text/xsl" href="xml_tree.xsl"?> <menu icon1="images/home.gif" caption="Books & Publications"> <menuItem caption="Science Fiction"> <menuItem action="17" title="Worst Case Scenario" caption="Tanwani Anyangwe"></menuItem> <menuItem action="4" title="Jurasic Park" caption="Micheal Crichton"></menuItem> <menuItem action="3" title="Star Wars" caption="George Lucas"></menuItem> </menuItem> <menuItem caption="Cold War" opened="false" icon1="images/refresh.png"> <menuItem action="10" caption="The Forth Protocol"></menuItem> <menuItem action="3" caption="Fire Fox"></menuItem> <menuItem action="31" caption="United Artists"> <menuItem action="310" caption="Dr. No" /> <menuItem action="311" caption="From Russia with Love" /> <menuItem action="1" caption="Live & Let Die" /> <menuItem action="31" caption="Diamonds are Foreever" /> <menuItem action="31" caption="Never Say Never Again" /> <menuItem action="31" caption="For you eyes only" /> <menuItem caption="Eastern Block Fictions" icon1="images/closed.gif" icon2="images/open.gif"> <menuItem action="10" caption="The Forth Protocol"></menuItem> <menuItem action="3" caption="Fire Fox"></menuItem> <menuItem action="31" caption="James Bond (007)"> <menuItem action="310" caption="Dr. No" /> <menuItem action="311" caption="From Russia with Love" /> <menuItem action="1" caption="Live & Let Die" /> <menuItem action="31" caption="Diamonds are Foreever" /> <menuItem action="31" caption="Never Say Never Again" /> <menuItem action="31" caption="For you eyes only" /> </menuItem> <menuItem action="13" caption="Maya Durashka"></menuItem> </menuItem> </menuItem> <menuItem action="13" caption="Maya Durashka"></menuItem> </menuItem> <menuItem icon1="images/copy.small.png" caption="Western Herritage"> <menuItem action="10" title="Tom Sawyer" caption="Mark Twain"></menuItem> <menuItem action="70" title="Roots" caption="Alex Harley"></menuItem> </menuItem> <menuItem icon1="images/notepad.png" caption="African American Herritage"> <menuItem action="70" title="Roots" caption="Alex Harley"></menuItem> </menuItem> </menu> </body> </html> nothing is shown, but in the html code there is the exact code with the xml file inside. then i have deleted the: Code:
<?xml-stylesheet type="text/xsl" href="xml_tree.xsl"?> (is this what you said to do?) but the result is the same as above... what should i have to do to have this xml file run into a html (or better php) page inside a div section? for example to have: <html> ... <div id=menu> xml code here (or a php include(xml file) statement) </div> ... </html> please just one more hint ![]() |
|
#4
|
||||
|
||||
|
this is my method for php5....
let me look around my hard drive and see if I still have the php4 script to do the same. Basically what this does is: you give it the xml and the xsl file and PHP runs the xsl parser and will output the result of the transformation to the client. PHP Code:
edit: here is a link for php4 sablotron way http://www.phpbuilder.com/columns/j...025.php3?page=4 Last edited by Teflon : October 6th, 2004 at 08:56 AM. Reason: added link for php4 sablotron method |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > embedding xml file into a php page (newbie) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|