iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-30-2008, 01:45 AM
subho's Avatar
WebProWorld Member
 
Join Date: Sep 2005
Location: India
Posts: 87
subho RepRank 0
Default XML data fetching using PHP

Hello everyone

I am new to php and stuck somewhere in php+xml. I have an .xml file where inside "title" tag there is website's "title", below inside "keyword" tags there are "meta keywords" of the website. I want to fetch the different data from that xml file and show it in proper place. How to do this?? any idea?

But there shouldnt be two different xml file....all the datas will be stored inside that xml file only.

Here is my .xml example::

<?xml version="1.0" encoding="iso-8859-1"?>
<phrase>
<title>Title goes here</title>
<keyword>mykeyword one</keyword>
<keyword>mykeyword two</keyword>
<keyword>mykeyword three</keyword>
</phrase>

Please help me..

Regards-
__________________
Developersouvik [Technology & creativity Spun together]
http://developersouvik.orgfree.com
Reply With Quote
  #2 (permalink)  
Old 11-26-2008, 01:05 AM
Moderator
WebProWorld Moderator
 
Join Date: Oct 2003
Location: Alberta, Canada
Posts: 878
weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6weegillis RepRank 6
Default Re: XML data fetching using PHP

If you're new to this like I am you will find this xslt stylesheet quite revealing. It was a lot of fun to create:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet  [
	<!ENTITY nbsp   "*">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<xsl:variable name="header">
    <tr bgcolor="#cccccc">
      <th style="text-align:left;width:10%">ID</th>
      <th style="text-align:left;width:60%">Course Name</th>
      <th style="text-align:left;width:30%">Instructor Name</th>
    </tr>
</xsl:variable>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>

 <table style="width:100%;border-collapse:collapse;border:none;font:normal 0.7em 'Trebuchet MS',Arial,sans-serif">
  <xsl:copy-of select="$header" />
  <xsl:for-each select="document/row">
  <tr>
   <td><xsl:value-of select="id"/></td>
   <td>
    <a>
    <xsl:attribute name="href" >
    index.php?id=<xsl:value-of select="courseid"/>
    </xsl:attribute>
    <xsl:attribute name="target" >
    _top
    </xsl:attribute>
    <xsl:value-of select="coursename"/>
    </a>
   </td>
   <td>
    <a>
    <xsl:attribute name="href" >
    /instructors/index.php?id=<xsl:value-of select="instructorid"/>
    </xsl:attribute>
    <xsl:attribute name="target" >
    _top
    </xsl:attribute>
    <xsl:value-of select="instructorname"/>
    </a>
   </td>
  </tr>
  </xsl:for-each>
 </table>
 
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The data being parsed is seven columns by N records, with links being affixed to text in one column from data stored in another. Only three of the columns are actually displayed. This particular example is live in an iframe. Sadly it does not get parsed in PHP, but by the browser.

If you get an answer to your question it's hoped I may get an answer to mine. I've included this example to illustrate the relationship between the data set and the style sheet template. Like many of my projects, this is a scratch on the surface but it works, for now, until a php solution can be found.

Here is a segment of the xml. Note the stylesheet element...
Code:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="courses.xsl" ?>
<document>
 <row>
  <id>1</id>
  <courseid>stress_perception</courseid>
  <coursename>All Stressed Up and No Place to Go</coursename>
  <instructorid>deb_milne</instructorid>
  <instructorname>Deb Milne</instructorname>
  <objective>1</objective>
  <flag>1</flag>
 </row>
 <row>
  <id>2</id>
  <courseid>asist</courseid>
  <coursename>Applied Suicide Intervention Skills Training</coursename>
  <instructorid>csp_asist</instructorid>
  <instructorname>Center for Suicide Prevention</instructorname>
  <objective>1</objective>
  <flag>1</flag>
 </row>
 <row>
  <id>3</id>
  <courseid>first_aid_training</courseid>
  <coursename>St. John Ambulance First Aid</coursename>
  <instructorid>st_john_ambulance</instructorid>
  <instructorname>St. John Ambulance Training</instructorname>
  <objective>1</objective>
  <flag>1</flag>
 </row>
 <row>
  <id>4</id>
  <courseid>cpr-aed</courseid>
  <coursename>St. John Ambulance CPR-AED</coursename>
  <instructorid>st_john_ambulance</instructorid>
  <instructorname>St. John Ambulance Training</instructorname>
  <objective>1</objective>
  <flag>1</flag>
 </row>
 <row>
  <id>5</id>
  <courseid>food_safety</courseid>
  <coursename>Food Safety</coursename>
  <instructorid>thor_hameister</instructorid>
  <instructorname>Thor Hameister</instructorname>
  <objective>1</objective>
  <flag>1</flag>
 </row>
</document>
Here is the XHTML to load the styled xml in an iframe:
Code:
 <table id="coursetable" summary="" class="layout pagecore">
  <tr><td class="leftbar">&nbsp;</td>
   <td class="contentbox">
    <div class="shell" style="margin-bottom:1em">
     <h2><a href="index.xml" title="full Course and Instructor table">Table of Courses and Instructors</a></h2>
     <iframe src="courses.xml" name="cwtable" width="100%" style="border:none">
      If you can see this, your browser doesn&rsquo;t understand IFRAME. View the
      <a href="index.xml" target="_blank"> full Course and Instructor table</a> in a new window.
     </iframe>
    </div>
   </td>
  </tr>
  </table>

Last edited by weegillis; 11-26-2008 at 01:23 AM. Reason: Adding omitted html code
Reply With Quote
  #3 (permalink)  
Old 11-26-2008, 10:25 AM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,629
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: XML data fetching using PHP

For my web site I parse numerous XML files with PHP and use that data to populate databases, as well as generate web pages from the data. There is a free and open source library that I use to power this functionality, called nusoap. The library is very powerful and includes tools to parse a variety of types of web services. The drawback is that the documentation is non-existant. However, you may be able to find instructions for simply parsing an XML file through the library. The system works by converting the data in the feed into an array that can then be used by your PHP script to display or process the data.
__________________
The best way to learn anything, is to question everything.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i separate adwords data in Google Analytics from organic data inertia Google Discussion Forum 8 08-20-2008 12:10 PM
Post Impression data for Keyword Search/CPC data? phunklord Marketing Strategies Discussion Forum 2 07-21-2005 08:16 AM
Google Showing Different data at different data centers Yatin Google Discussion Forum 1 02-25-2005 08:01 AM
Free Data Merchant Data Cleaner - Beta Release Chris - WSO Affiliate Marketing Discussion Forum 2 12-27-2004 10:19 PM
Using MLS data oneeye Graphics & Design Discussion Forum 10 06-04-2004 09:15 PM


All times are GMT -4. The time now is 11:26 PM.



Search Engine Optimization by vBSEO 3.3.0