XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 5th, 2004, 09:16 AM
diblasid diblasid is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 diblasid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old October 6th, 2004, 07:18 AM
Teflon's Avatar
Teflon Teflon is offline
Teflon The Black
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Woodbridge VA
Posts: 246 Teflon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 14 sec
Reputation Power: 5
Send a message via AIM to Teflon
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>

Reply With Quote
  #3  
Old October 6th, 2004, 08:27 AM
diblasid diblasid is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 diblasid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old October 6th, 2004, 08:50 AM
Teflon's Avatar
Teflon Teflon is offline
Teflon The Black
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Woodbridge VA
Posts: 246 Teflon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 14 sec
Reputation Power: 5
Send a message via AIM to Teflon
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:
<html>
<
head></head>
<
body>
<
h3>Something goes here</h3>
<?

    
$xmlfile "test.xml";
    
$xslfile "xml_tree.xsl";

/* Load the two XML sources */
$xml = new DomDocument;
$xml->load($xmlfile);

$xsl = new DomDocument;
$xsl->load($xslfile);

/* Configure the transformer */
$proc = new xsltprocessor;
$proc->registerPhpFunctions();
$proc->importStyleSheet($xsl); // attach the xsl rules

echo $proc->transformToXML($xml);


?>
<h2>Something else goes here</h2>

</body>
</html> 


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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > embedding xml file into a php page (newbie)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT