The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 21, 2019, 12:28:29 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Learning xml feeding with php  (Read 4314 times)
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« on: March 31, 2008, 02:05:03 PM »


I think it would be cool to learn how to use xml feeding with php. Reason for this thread is that I want your help and suggestions on how to do things even simpler and cleaner or if I'm doing this totally wrong.

Goal:
Create a simpel xml feed

Objectives:
Script must use DOM tree to handle xml to simplify coding and resuseability (I think it will   )
Script must work on shared hosting

Tactics:
I will use a class called PhpXPath for DOM handling. This doesnt need DOM package to work. I think I had a problem with this before on resellerzoom.

You can find out more about this class here:
http://pear.php.net/package/XML_XPath
http://sourceforge.net/projects/phpxpath

I have no clue if this will work or if I need some extra things to make this work. If I make this work I will post the source code here.
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: March 31, 2008, 02:17:52 PM »

Listen to you, all goals objectives and tactics and such...

Right on man Wink

Post away man, excellent plan.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #2 on: March 31, 2008, 02:20:00 PM »

Whoa hey, don't bite down hard with Perk's dong in there!
Logged

hai
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: March 31, 2008, 02:46:34 PM »

 ROFLMAO ROFLMAO ROFLMAO ROFLMAO
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #4 on: March 31, 2008, 03:37:28 PM »

Are you planning on using PHP 4 or 5? If the latter then the DOM functionality you need is already built in.

DM
Logged
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« Reply #5 on: March 31, 2008, 03:40:09 PM »

 Grin Grin Grin Grin ROFLMAO  Smooch  Smooch Smooch

Trying to improve myself so I follow perks suggestion on syndk8. I must practise goals, tactics, objectives and strategy. Just to get a feeling for it. Any  suggestion to improve this is most appreciated.

I have some small sample code here if you're trying the same as me. Not finished yet.

require_once("XPath.class.php");

$xPath = new XPath("test.xml");
$nodeCollection = $xPath->match("//fruit");
$xPath->insertChild("/sentence[1]/fruit[1]","<test></test>");
$export = $xPath->exportAsXml();
print_r($export); //This must be used in view source to see the xml.

This is the xml:
<?xml version="1.0"?>
<sentence>
Today in the market, I spy
<vegetable color='green'>cabbages</vegetable>,
<fruit color='red'>apples</fruit>,
<fruit color='green'>pears</fruit>,
<vegetable color='purple'>aubergines</vegetable>, and
<fruit color='orange'>oranges</fruit>
</sentence>

Happy coding. Ohh I forget. This is for you perk  Smooch


Logged
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« Reply #6 on: March 31, 2008, 03:41:26 PM »

Are you planning on using PHP 4 or 5? If the latter then the DOM functionality you need is already built in.

DM

PHP 4
Script must work on shared hosting  Smiley
Well I should change it to
Script must work on most shared hosting
« Last Edit: March 31, 2008, 03:43:31 PM by nattsurfaren » Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #7 on: March 31, 2008, 04:38:27 PM »

Writing your own XML parser is not trivial. I will post my class so that you can use that in your research. My functional methodology is different than the DOM, but I think the names of the functions will be self explanatory.

Note that the class is bidirectional ie., you can parse/walk existing XML or create new records on the fly really easily.

You'll see it in the Show All Unread in just a bit.

/p

<edit>A benefit of this class is that it is all PHP4 and requires no additional libs at all, it will work on the cheapest hosts around.</edit>
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« Reply #8 on: April 01, 2008, 02:55:49 AM »

Very nice, thanks. I will have a go of it.  Praise
Logged
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« Reply #9 on: April 04, 2008, 12:20:15 PM »

I have successfully added an rss feed to squidoo.
Here is the code I used to produce the feed.

Code:
<?php

/* TODO: Add code here */
require_once("xmlhandler.php");
$xml = new xmlHandler();
$xml->importXML("<?xml version=\"1.0\" ?>
\r\n<rss version=\"2.0\"></rss>");

$xml->addChild("channel","",true);
$xml->addChild("title","My secret feed");
$xml->addChild("description","This is my feed for all pretty women in the world");
$xml->addChild("item","",true);
$xml->addChild("title","Nattsurfaren nude in the shower");
$xml->addChild("description","Yes you can see me nude on webcam live. 30 min = $100, 1hr=$200, 2hr=$1000. Pay with paypal, visa, mastercard",false);
$xml->addChild("link","http://nudecam.com/natt.htm");/*/**/
$xml->moveToRoot();
$export=$xml->outputAllXML(true);
print $export;
?>
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #10 on: April 05, 2008, 12:03:03 AM »

Nice natt, nice to see it working for you.

But not necessarily nice to see so much of you  ROFLMAO
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!