MYSQL获取xml字符串,无需转换/解释

Simple requirement: I want to store a flat unchanged XML strings into a MySQL-DB and then fetch the string itself via php with the tags (i.e. <tag>1234</tag>).

Problem: When I fetch the string, I get the values not the entire XML string.

I store <tag>1243</tag> (done via PHPmyAdmin) then I fetch (see code below) and echo the result I get 1234 not <tag>1234</tag>.

$query = "SELECT * FROM  " . $my_table_with_flat_xml_string;
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
  $xml_flat_file_with_the_tags_please = $row[0];
  echo " ( " . $tags. ")";
}

Help!

Every node has a "name" (e.g. "tag") and a value (e.g. "1234", or perhaps "empty").

You've got the value.

You simply want to store the name, too. Twice.

By creating the string "<" . $name . ">" . $value . ""

There are several different ways to get $name and $value - it all depends on exactly how you're parsing your XML file.

Here's an excellent tutorial that gives you details on using XML from PHP:

The String fetched from the database is <tag>1234</tag> as you put it into the database. MySQL does not interpret or parse XML input as long as you don't tell it to.

But you only echo it without escaping the < and >-chars, so your browser thinks, this would be a HTML-Element.

You can use something like the var_dump()-function to print out your fetched value or you escape the brackets by using the htmlspecialchars()-function.