I'm exporting a MySQL database as XML using mysqldump -x. Many of my fields contain apostrophes and other characters which confuse mysqldump-x-restore's XSLT stylesheet.
我使用mysqldump -x将MySQL数据库导出为XML。我的许多字段都包含撇号和其他字符,这些字符混淆了mysqldump-x-restore的XSLT样式表。
It's not sufficient to just run through the file and escape the characters that XML has problems with, as that would replace every legal XML bracket and quote as well. Is there an option somewhere on mysqldump to do XML escaping on column data?
仅仅运行该文件并转义XML存在问题的字符是不够的,因为它将替换每个合法的XML括号和引号。 mysqldump上是否有选项可以对列数据进行XML转义?
1 个解决方案
#1
0
If only a few special characters results in trouble, you may achieve the same result as mysqldump -x with the execute (-e) option combined with REPLACE functions in the regular mysql client.
如果只有少数特殊字符会导致问题,则可以使用execute(-e)选项与常规mysql客户端中的REPLACE函数相结合,获得与mysqldump -x相同的结果。
Example that escapes the ampersand character:
转义&符号的示例:
mysql --xml -uusername -p -Ddatabasename -e"SELECT REPLACE(field1, '&', ' ') AS field1 FROM ymse.dbh_inst" > /path/file.xml
If you have to escape multiple special characters this method will lead to ugly nested REPLACE statments since MySQL don't support regexp replace.
如果你必须转义多个特殊字符,这个方法将导致丑陋的嵌套REPLACE语句,因为MySQL不支持regexp替换。
#1
0
If only a few special characters results in trouble, you may achieve the same result as mysqldump -x with the execute (-e) option combined with REPLACE functions in the regular mysql client.
如果只有少数特殊字符会导致问题,则可以使用execute(-e)选项与常规mysql客户端中的REPLACE函数相结合,获得与mysqldump -x相同的结果。
Example that escapes the ampersand character:
转义&符号的示例:
mysql --xml -uusername -p -Ddatabasename -e"SELECT REPLACE(field1, '&', ' ') AS field1 FROM ymse.dbh_inst" > /path/file.xml
If you have to escape multiple special characters this method will lead to ugly nested REPLACE statments since MySQL don't support regexp replace.
如果你必须转义多个特殊字符,这个方法将导致丑陋的嵌套REPLACE语句,因为MySQL不支持regexp替换。