SunQuest
           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:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old July 3rd, 2002, 02:56 AM
Requiem Requiem is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 1 Requiem User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Bloody Stupid Question #1

Sorry for this, but we all have to start somewhere...

Using PHP and MySQL, how do I get data from a XML document into the database? I know by using DOM, but does that mean that the DOM parser will write all the data to the database?!? Or does it store it in variables?!?

Help guys! I'm feeling pretty damn stupid here, but need a bunch of stupid questions answered.

Best

Stiaan

Reply With Quote
  #2  
Old July 3rd, 2002, 03:19 AM
binky's Avatar
binky binky is offline
Gerbil
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2001
Location: In a Rotastak
Posts: 1,763 binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 22 h 12 m 52 sec
Reputation Power: 18
Read the XML file into arrays then do sql statements. There may be another way (probably) but that way serves me best. Something like:

PHP Code:
 $file "newsXML.xml";
    
$newsitem = array();
    
$id ""$text "";

    function 
startElement($parser$name$attribs) {
        global 
$id;
        if (
$name == 'NEWSITEM') {
            
$id $attribs['ID'];
        }        
    }

    function 
endElement($parser$name) {
        global 
$id;
        global 
$text;
        global 
$newsitem;
        if (
$name == 'HEADLINE') {
            
$newsitem[$id][0] = $text;
            
$text "";
        }
        if (
$name == 'NEWSTEXT') {
            
$newsitem[$id][1] = $text;
            
$text "";
        }

    }
    function 
characterData($parser$data) {
        global 
$text;
        
$text .= $data;
    }


    
$xml_parser xml_parser_create();
    
xml_set_element_handler($xml_parser"startElement""endElement");
    
xml_set_character_data_handler($xml_parser"characterData");

    
$fp fopen($file"r");

    while (
$data fread($fp4096)) {
            
xml_parse($xml_parser$datafeof($fp));
      }
    
xml_parser_free($xml_parser); 


That would give you an array of:
headline : $newsitem[id][0]
text of news item : $newsitem[id][1]

Then do a foreach()

to put it into a database.
__________________
- Sorted!

www.ppfuk.com - Free Photo Sharing

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Bloody Stupid Question #1


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway