sql - 如何将xml保存到mysql数据库?

标签 sql xml database parsing

我从原始链接中找到了这个: http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html#dev 例如

<?php
    function StartElement($parser, $name, $attrs) { 
        if (!empty($attrs['RATE'])) {
            echo "1&euro;=".$attrs['RATE']." ".$attrs['CURRENCY']."<br />"; 
        }
    }
    $xml_parser= xml_parser_create();
    xml_set_element_handler($xml_parser, "StartElement", "");
    // for the following command you will need file_get_contents (PHP >= 4.3.0) 
    // and the config option allow_url_fopen=On (default)
    xml_parse($xml_parser, file_get_contents ("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"));
    xml_parser_free($xml_parser);
?>

然后看起来像:

INSERT INTO `curr_table` (`curr_id`, `curr_title`, `Code`, `decimal_place`, `value`) VALUES
(1, 'EURO', 'EUR', '2', 1.3917),
(2, 'Japan Yen', 'JPY', '2', 112.88),
(3, 'Bla..bla', 'BGN', '2', 1.9558),
..............................etc
(20, 'Bla..bla.', 'CZK', '2', 24.575);

任何指针和示例代码将不胜感激并提前致谢

最佳答案

如果您使用的是 MySQL 5.1 或更新版本,则有 XML 支持:

http://dev.mysql.com/tech-resources/articles/xml-in-mysql5.1-6.0.html#xml-5.1-in-and-out

关于sql - 如何将xml保存到mysql数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4130440/

相关文章:

带时区的 XML 日期时间

android - android水平均匀地放置空间按钮

sql - 在表中 Access VBA 搜索和替换

文本修订的数据库设计

mysql - SQL - 理解 'JOIN' 语法、顺序

sql - 计算一段时间后或基于辅助列的重复出现次数

MySQL 在大型数据集上使用 IN 更新时速度缓慢

sql - 应用程序配置或应用程序选项设置的最佳表格设计?

java - 如何在java中处理xml内容中的标签

Java - 无法从静态上下文引用非静态方法