2017-07-05 1 views
0

私はこのようなXMLファイルを持っている:私はそれをデータベースに格納することができるように行と列に変換したいXamppでMariaDBを使用して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="&lt;p&gt;I am:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the co-  
founof &lt;a href=&quot;http://om&quot;&gt;Stack 
Ext;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;the of &lt;a 
href=&quot;http://wwwkot; rel=&quot;nofollow&quot;&gt;Fog 
Slt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;the creatorrman 
of the board of &lt;a href=&quot;http://trello.com&quot; 
rel=&quot;nofollow&quot;&gt;Trello&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;owner 
of Taco, the most f Husky on the UWest  
Side.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You can find me on 
Twitter (as &lt;a href=&quot;http://twitlsky&quot; 
rel=&quot;nofollow&quot;&gt;@sky&lt;/a&gt;) or on my rarely-updated 
blog, &lt;a href=&quot;http://joecom&quot; 
rel=&quot;nofollow&quot;&gt;Software&lt;/a&gt;.&lt;/p&gt;&#xA;" 

Views="69136" UpVotes="785" DownVotes="96" 

ProfileImageUrl="https://i.stam/C5gBG.jpg?s=128&amp;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を使用しています。

EDIT:バージョン10.1.19-MariaDB

答えて

0

私は問題を再現することはできません。

を参照してくださいテスト:

ファイル:/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="&lt;p&gt;I am:&lt;/ p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the co-  
founof &lt;a href=&quot;http://om&quot;&gt;Stack 
Ext;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;the of &lt;a 
href=&quot;http://wwwkot; rel=&quot;nofollow&quot;&gt;Fog 
Slt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;the creatorrman 
of the board of &lt;a href=&quot;http://trello.com&quot; 
rel=&quot;nofollow&quot;&gt;Trello&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;owner of Taco, the most f Husky on the UWest Side.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You can find me on Twitter (as &lt;a href=&quot;http://twitlsky&quot; 
rel=&quot;nofollow&quot;&gt;@sky&lt;/a&gt;) or on my rarely-updated blog, &lt;a href=&quot;http://joecom&quot; 
rel=&quot;nofollow&quot;&gt;Software&lt;/a&gt;.&lt;/p&gt;&#xA;" 
     Views="69136" 
     UpVotes="785" 
     DownVotes="96" 
     ProfileImageUrl="https://i.stam/C5gBG.jpg?s=128&amp;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>&#xA;&#xA;<ul>&#xA;<li>the co-  
founof <a href="http://om">Stack 
Ext;/a></li>&#xA;<li>the of <a 
href="http://wwwkot; rel="nofollow">Fog 
Slt;/a></li>&#xA;<li>the creatorrman 
of the board of <a href="http://trello.com" 
rel="nofollow">Trello</a></li>&#xA;<li>owner of Taco, the most f Husky on the UWest Side.</li>&#xA;</ul>&#xA;&#xA;<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>&#xA; 
      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を参照してください。

UPDATE

チェックサーバのシステム変数local_infileの値:

MariaDB [_]> SHOW VARIABLES WHERE `Variable_name` = 'local_infile'; 
+---------------+-------+ 
| Variable_name | Value | 
+---------------+-------+ 
| local_infile | ON | 
+---------------+-------+ 
1 row in set (0.01 sec) 
+0

は、64ビットの問題対32ビットであるように。私は32ビットシステム上で、Xamppを介してMariaDBを実行しています。私はあなたがした同じ手順を複製し、同じエラーが発生しました。 –

+0

@TheDoctor:更新された回答を参照してください。 – wchiquito

関連する問題