如何在 Xampp 上使用 MariaDB 将 XML 文件转换为行和列?
Posted
技术标签:
【中文标题】如何在 Xampp 上使用 MariaDB 将 XML 文件转换为行和列?【英文标题】:How to convert an XML file to rows and columns using MariaDB on Xampp? 【发布时间】:2017-12-09 04:53:29 【问题描述】:我有一个如下所示的 XML 文件:
<users>
<row Id="4" Reputation="27228" CreationDate="2008-07-31T14:22:31.317"
DisplayName="abc"
LastAccessDate="2017-8:19:58.113"
WebsiteUrl="http://www.joeware.com/" Location="Nerk, NY"
AboutMe="<p>I am:</p>

<ul>
<li>the co-
founof <a href="http://om">Stack
Ext;/a></li>
<li>the of <a
href="http://wwwkot; rel="nofollow">Fog
Slt;/a></li>
<li>the creatorrman
of the board of <a href="http://trello.com"
rel="nofollow">Trello</a></li>
<li>owner
of Taco, the most f Husky on the UWest
Side.</li>
</ul>

<p>You can find me on
Twitter (as <a href="http://twitlsky"
rel="nofollow">@sky</a>) or on my rarely-updated
blog, <a href="http://joecom"
rel="nofollow">Software</a>.</p>
"
Views="69136" UpVotes="785" DownVotes="96"
ProfileImageUrl="https://i.stam/C5gBG.jpg?s=128&g=1"
AccountId="4" />
</users>
我希望将其转换为行和列,以便可以将其存储在数据库中。我在 MariaDB 上尝试了以下操作:
LOAD XML LOCAL INFILE '<path>.xml'
-> INTO TABLE mytbl(id, rep, c_date, D_name,...);
但它导致错误 ERROR 1148 (42000): The used command is not allowed with this MariaDB version
。怎么出去把xml文件转成行和表?
我在 Xampp 上使用 MariaDB。
编辑:版本 10.1.19-MariaDB
【问题讨论】:
【参考方案1】:我无法重现该问题。
查看测试:
文件:/path/to/file.xml
<users>
<row Id="4"
Reputation="27228"
CreationDate="2008-07-31T14:22:31.317"
DisplayName="abc"
LastAccessDate="2017-8:19:58.113"
WebsiteUrl="http://www.joeware.com/"
Location="Nerk, NY"
AboutMe="<p>I am:</ p>

<ul>
<li>the co-
founof <a href="http://om">Stack
Ext;/a></li>
<li>the of <a
href="http://wwwkot; rel="nofollow">Fog
Slt;/a></li>
<li>the creatorrman
of the board of <a href="http://trello.com"
rel="nofollow">Trello</a></li>
<li>owner of Taco, the most f Husky on the UWest Side.</li>
</ul>

<p>You can find me on Twitter (as <a href="http://twitlsky"
rel="nofollow">@sky</a>) or on my rarely-updated blog, <a href="http://joecom"
rel="nofollow">Software</a>.</p>
"
Views="69136"
UpVotes="785"
DownVotes="96"
ProfileImageUrl="https://i.stam/C5gBG.jpg?s=128&g=1"
AccountId="4" />
</users>
MariaDB 命令行:
MariaDB [_]> SELECT VERSION();
+-----------------+
| VERSION() |
+-----------------+
| 10.1.19-MariaDB |
+-----------------+
1 row in set (0.00 sec)
MariaDB [_]> DROP TABLE IF EXISTS `mytbl`;
Query OK, 0 rows affected (0.00 sec)
MariaDB [_]> CREATE TABLE IF NOT EXISTS `mytbl` (
-> `id` TEXT,
-> `rep` TEXT,
-> `c_date` TEXT,
-> `D_name` TEXT,
-> `LastAccessDate` TEXT,
-> `WebsiteUrl` TEXT,
-> `Location` TEXT,
-> `AboutMe` TEXT,
-> `Views` TEXT,
-> `UpVotes` TEXT,
-> `DownVotes` TEXT,
-> `ProfileImageUrl` TEXT,
-> `AccountId` TEXT
-> );
Query OK, 0 rows affected (0.00 sec)
MariaDB [_]> LOAD XML LOCAL INFILE '/path/to/file.xml'
-> INTO TABLE `mytbl` (
-> @`Id`,
-> @`Reputation`,
-> @`CreationDate`,
-> @`DisplayName`,
-> @`LastAccessDate`,
-> @`WebsiteUrl`,
-> @`Location`,
-> @`AboutMe`,
-> @`Views`,
-> @`UpVotes`,
-> @`DownVotes`,
-> @`ProfileImageUrl`,
-> @`AccountId`
-> )
-> SET
-> `id` = @`Id`,
-> `rep` = @`Reputation`,
-> `c_date` = @`CreationDate`,
-> `D_name` = @`DisplayName`,
-> `LastAccessDate` = @`LastAccessDate`,
-> `WebsiteUrl` = @`WebsiteUrl`,
-> `Location` = @`Location`,
-> `AboutMe` = @`AboutMe`,
-> `Views` = @`Views`,
-> `UpVotes` = @`UpVotes`,
-> `DownVotes` = @`DownVotes`,
-> `ProfileImageUrl` = @`ProfileImageUrl`,
-> `AccountId` = @`AccountId`;
Query OK, 1 row affected (0.00 sec)
Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
MariaDB [_]> SELECT
-> `id`,
-> `rep`,
-> `c_date`,
-> `D_name`,
-> `LastAccessDate`,
-> `WebsiteUrl`,
-> `Location`,
-> `AboutMe`,
-> `Views`,
-> `UpVotes`,
-> `DownVotes`,
-> `ProfileImageUrl`,
-> `AccountId`
-> FROM
-> `mytbl`\G
*************************** 1. row ***************************
id: 4
rep: 27228
c_date: 2008-07-31T14:22:31.317
D_name: abc
LastAccessDate: 2017-8:19:58.113
WebsiteUrl: http://www.joeware.com/
Location: Nerk, NY
AboutMe: <p>I am:</ p>

<ul>
<li>the co-
founof <a href="http://om">Stack
Ext;/a></li>
<li>the of <a
href="http://wwwkot; rel="nofollow">Fog
Slt;/a></li>
<li>the creatorrman
of the board of <a href="http://trello.com"
rel="nofollow">Trello</a></li>
<li>owner of Taco, the most f Husky on the UWest Side.</li>
</ul>

<p>You can find me on Twitter (as <a href="http://twitlsky"
rel="nofollow">@sky</a>) or on my rarely-updated blog, <a href="http://joecom"
rel="nofollow">Software</a>.</p>

Views: 69136
UpVotes: 785
DownVotes: 96
ProfileImageUrl: https://i.stam/C5gBG.jpg?s=128&g=1
AccountId: 4
1 row in set (0.00 sec)
见LOAD XML。
更新
检查服务器系统变量local_infile的值:
MariaDB [_]> SHOW VARIABLES WHERE `Variable_name` = 'local_infile';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile | ON |
+---------------+-------+
1 row in set (0.01 sec)
【讨论】:
可能是 32 位与 64 位的问题。我在 32 位系统上并通过 Xampp 运行 MariaDB。我复制了您执行的确切步骤,但仍然遇到相同的错误。以上是关于如何在 Xampp 上使用 MariaDB 将 XML 文件转换为行和列?的主要内容,如果未能解决你的问题,请参考以下文章