Jump to content

tutorial required for xml upload


burge124

Recommended Posts

Download this class and use it like this

 

<?php
include_once("class_path_parser.php");
include ("include/xml-fonc.php");

$parser1->set_handler("/STHS-Coaches/Coach/Name","xml_to_db1");
$parser1->set_handler("/STHS-Coaches/Coach/Team","xml_to_db1");
$parser1->set_handler("/STHS-Coaches/Coach/Country","xml_to_db1");
$parser1->set_handler("/STHS-Coaches/Coach/Age","xml_to_db1");
$parser1->set_handler("/STHS-Coaches/Coach/PH","xml_to_db1");
$parser1->set_handler("/STHS-Coaches/Coach/DF","xml_to_db1");
$parser1->set_handler("/STHS-Coaches/Coach/OF","xml_to_db1");
$parser1->set_handler("/STHS-Coaches/Coach/PD","xml_to_db1");
$parser1->set_handler("/STHS-Coaches/Coach/EX","xml_to_db1");
$parser1->set_handler("/STHS-Coaches/Coach/LD","xml_to_db1");
$parser1->set_handler("/STHS-Coaches/Coach/PO","xml_to_db1");
$parser1->set_handler("/STHS-Coaches/Coach/Contrac","xml_to_db1");
$parser1->set_handler("/STHS-Coaches/Coach/Salary","xml_to_db1");
if(!$parser1->parse_file("include/xml/LNHSP3-Coaches.xml")) {
  print("Error:".$parser1->get_error()."<br/>\n"); 
}else{
echo "LNHSP3-Coaches.xml parsed!<br>";	
}

$parser2 = new Path_parser();
$parser2->set_handler("/STHS-FarmTeam/Team/Name","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/Abbre","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/Morale","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/Point","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/GP","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/W","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/L","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/T","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/OTW","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/OTL","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/SOW","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/SOL","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/GF","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/GA","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/HomeGP","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/HomeW","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/HomeL","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/HomeT","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/HomeOTW","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/HomeOTL","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/HomeSOW","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/HomeSOL","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/HomeGF","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/HomeGA","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/PPAttemp","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/PPGoal","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/PKAttemp","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/PKGoalGA","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/PKGoalGF","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/ShotsFor","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/ShotsAga","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/ShotsBlock","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/ShotsPerPeriod1","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/ShotsPerPeriod2","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/ShotsPerPeriod3","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/ShotsPerPeriod4","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/GoalsPerPeriod1","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/GoalsPerPeriod2","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/GoalsPerPeriod3","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/GoalsPerPeriod4","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/Shutouts","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/Goals","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/Assists","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/Points","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/Pim","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/Hits","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/FaceOffWonOF","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/FaceOffWonDF","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/FaceOffWonNT","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/FaceOffTotalOF","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/FaceOffTotalDF","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/FaceOffTotalNT","xml_to_db2");
$parser2->set_handler("/STHS-FarmTeam/Team/EmptyNetGoal","xml_to_db2");
if(!$parser2->parse_file("include/xml/LNHSP3-FarmTeam.xml")) {
  print("Error:".$parser2->get_error()."<br/>\n"); 
}
echo "LNHSP3-FarmTeam.xml parsed!<br>";
?>

 

I included in attachement the 2 XML files i used in this exemple, the class and function page I hope thats gona help.

http://versatilebb.com/XML_to_DB.rar

 

I am gona delete it when you confirme you dowloaded it

Link to comment
Share on other sites

hi, any other ways of completing this task?

 

the xml layout i must use is...

 

<?xml version="1.0" encoding="ISO-8859-1"?>
<question>
<chapter>
   	*** ENTER CHAPTER NAME HERE ***
   	</chapter>
<questiontitle>
*** ENTER SOURCE OF QUESTION/ANSWER ***
	</questiontitle>
<answera>
*** ENTER ANSWER A HERE ***
   	</answera>
<answerb>
*** ENTER ANSWER B HERE ***
   	</answerb>
<answerc>
*** ENTER ANSWER C HERE ***
   	</answerc>
<correctanswer>
*** ENTER CORRECT ANSWER HERE ( A B C ) ***
   	</correctanswer>
</question>

 

 

and the database layout to accept the xml is...

table - question

column names - QuestionTitle, AnswerA, AnswerB, AnswerC, CorrectAnswer

thanks

 

 

Link to comment
Share on other sites

Then you also need to change the function name in the xml-fonc.php page

 

function xml_to_questiondb($name,$attribs,$content) {

 

if ($content!=""){

$content = explode("<$name>", $content);

$content = explode("</$name>", $content[1]);

$content[0]=addslashes($content[0]);

}

 

if ($name=="Name"){

$enter = mysql_query("INSERT INTO coach (id, name) VALUE ('', '$content[0]')") or die (mysql_error());

}else{

if ($content!=""){

$coach_select = mysql_query("SELECT * FROM coach order by id desc limit 0,1") or die (mysql_error());

$coach = mysql_fetch_array($coach_select);

$enter = mysql_query("UPDATE coach SET $name='$content[0]' WHERE id='$coach[id]'") or die (mysql_error());

}

}

 

}

 

And of course change for your info

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.