Page 1 of 1

simpleXML MySQL : Store XML in MySQL Table

Posted: Thu Apr 05, 2007 6:54 am
by pras2309
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I m new in XML and I have got a problem regarding the XML and MySQL. 

Application Scenario:

I have a XML structure which needs to store the contents - 
heading,
subheading and 
the matter
I have a form to take the input from the user, and the user can put any type of data into the XML with specialcharacters and of the different languages and the html as well.
I am using the simpleXML to Create/Update the xml and its contents. At the end the xml is to be stored in the database.


My Problem:
If the user data consists of the special characters like apostrophy, doublequotes, and others special characters of the other languages, it is not storing in the XML. 

[b]In nut shell: [/b]
I have to make a form store the form data in XML and further store the XML in MySQL table.

What should I do? 

I have tried to encode the data using various php functions. Here is the sample code. If you viewsource the data the last line displayed on the browser I want to store in the XML, so that If it get displayed on the browser I will look as the user wants to see,  but failed to do so.

Please help me out.

Best Regards

Prashant

Code: Select all

<? 
echo "Part One <BR> ";
$val= utf8_encode($textarea); 
echo $val."<br>";
$val=utf8_decode($textarea);
echo $val;
echo "<BR>Part Two <BR>";
echo magic_quotes_runtime($textarea);
	$val= htmlentities($textarea,ENT_QUOTES);
	echo $val."<br>";
    echo stripslashes(htmlentities($textarea,ENT_QUOTES));


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body><form id="form1" name="form1"  method="post" action="test.php">
  <textarea name="textarea" cols="50" rows="15">@"'http://localhost:81/admin/manageXMLpage_test.php5 " " " " " " ` ` ` `' ' '     'asdf af '"</textarea>
  <input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>

My XML Structure

Code: Select all

<contents>
<content id="1">
<heading></heading>
<subheading></subheading>
<txtmatter></txtmatter>
</content>[/quote][/quote]
</contents>


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Apr 05, 2007 12:13 pm
by Kieran Huggins
I'm not sure exactly what your problem is... but here are some suggestions anyway:

Storing your XML in the DB: base64 encode it. You can also add columns for fields you want to index with, like "heading" etc...

displaying in an HTML form: htmlentities() should work if you're putting it in a textarea.