4 Replies - 13271 Views - Last Post: 06 September 2010 - 11:10 PM Rate Topic: -----

#1 andalusia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 06-September 10

how to insert data from xml to mysql database

Posted 06 September 2010 - 07:26 PM

i got coding for classXml.inc

i want to read xml to insert all data from xml to mysql database..who can help me..
<?
class xml_parser_model{
		
		var $file_path;	
		var $data;
		var $item_found;
		var $id;
		var $fwdName;
		var $content;
		var $project_name;
		var $arr_convert;
		var $error;
		
		//get xml from file
		function set_data($file){
			
				$this->file_path=$file;
				
				//read xml_file
				$this->data=implode("", file($file));		
			
		}
		
		function skip_tag(){	
			
		}
		
		function check_error(){		
			
		}
		
		function parse_pimpsTenderId(){
			
                               			
				//create xml parser
				$xml = xml_parser_create();
				//parse xml
				xml_parse_into_struct($xml, $this->data, $vals, $index);
				xml_parser_free($xml);
				
				
				$this->id=NULL;
				$this->item_found=NULL;
				//print_r($vals); 
				
				foreach($vals as $no => $item){
						
						switch($item['tag']){
							
							case "ID" :  $this->project_name=$item['value']; 
								break;

							case "TITLE" : $this->fwdName=$item['value'];
								break;
							
							case "DESCRIPTION" : $this->content=$item['value'];
								break;
							
							case "PROPERTY" : $this->id++;
											  $this->arr_convert[$this->id]['no']=$item['value'];									 
								break;

						}
						
					}
			
									
		}
		
		function parse_dsoft(){
			
			
		}
		
	}
?>

this is my xml ;

<?php
<project>
<name>saya</name>
<state>KL</state>
<sekolah>
<kebangsaan nama="skks" state="key el">sekolah rendah</kebangsaan >
<menengah name="smknb" state="johor">sekolah menengah</menengah>
<sekolah>
<files compresser="http;//hello.my/public/resource.php?name=push$amp;id=555444222111&amp;compressed=true">
    <file name="sekolahku.pdf" path="general">http://hello.my </file>  
    <file name="lahirku.pdf" path="drawing">http://hello.my </file>  
</files>
</project>
?>


This post has been edited by no2pencil: 06 September 2010 - 09:47 PM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: how to insert data from xml to mysql database

#2 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: how to insert data from xml to mysql database

Posted 06 September 2010 - 09:34 PM

No code tags, an unclear request, and an unfinished XML handler class. Not to mention malformed XML (in PHP tags, no less). What are you trying to do? Getting stuff from XML inserted into a MySQL database is clear, but that alone makes for a pretty vague question, especially when you post up malformed XML and very unfinished code that from the looks of it doesn't even attempt to use MySQL.
Was This Post Helpful? 0
  • +
  • -

#3 andalusia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 06-September 10

Re: how to insert data from xml to mysql database

Posted 06 September 2010 - 09:47 PM

simply, i don't know how to read the xml that have many attributes,
my first coding class xml_parser_model, i dont know how to get attributes from xml, it just get element from xml.

i want read the xml and all element and attributes in xml i want to insert into mysql database.
Was This Post Helpful? 0
  • +
  • -

#4 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: how to insert data from xml to mysql database

Posted 06 September 2010 - 09:55 PM

Have you considered working with SimpleXML? I wrote a tutorial on it some time ago, and while it's a little dated, it covers accessing attributes. You might find it helpful in this situation :)

This post has been edited by Valek: 06 September 2010 - 09:55 PM

Was This Post Helpful? 0
  • +
  • -

#5 andalusia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 06-September 10

Re: how to insert data from xml to mysql database

Posted 06 September 2010 - 11:10 PM

still cannot help me..

this page for display all result from xml..
<?php
include("neti_xml_parser_model.inc.php");
include("connect.php");

$xml_file="pimps.xml";
#$xml_data=implode("",file($xml_file)); //get XML data for alternative direct parsing

$xml_parser = new neti_xml_parser_model();
$xml_parser->set_data($xml_file);

$xml_parser->parse_pimpsTenderId();
		
		//get project name
		$project_name=$xml_parser->project_name;
		//get array of item
		$arr_convert=$xml_parser->arr_convert;
		//get item_found
		$item_found=$xml_parser->item_found;
		//get fwdName
		$fwdName=$xml_parser->fwdName;
		//get error
		$error=$xml_parser->error;
		$line=$xml_parser->line;

foreach($arr_convert as $key =>$result){

echo "$key = $result->_item";

}

echo "<BR>".$project_name."<BR>".$fwdName;	
		
//sql
//$sql = new Query("INSERT INTO myworld (name, state, neme_brand, name_state, content_brand, files_commpress, file_name, file_path) VALUES()");
//$result = $sql->fetchArray();

		
?>


from this page i want to display result from xml and insert to mysql database.
include("neti_xml_parser_model.inc.php"); = this page, i submit on first my question in this forum..

This post has been edited by andalusia: 06 September 2010 - 11:12 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1