如何将自定义XML文件导入MySQL?
我的XML:
<ObjectList>
<Section Index="0" Name="MichaelCat">
<Item Index="0" Slot="0" FirstNmae="Example1" LastName="Example2" Age="30" />
<Item Index="1" Slot="0" FirstNmae="Example1.2" LastName="Example2.1" Age="30" />
</Section>
<Section Index="1" Name="MichaelCat2">
<Item Index="0" Slot="0" FirstNmae="Example1" LastName="Example2" Age="30" />
<Item Index="1" Slot="0" FirstNmae="Example1.2" LastName="Example2.1" Age="30" />
</Section>
</ObjectList>
我的数据库架构:
SectionName | Section | Index | Slot | FIrstName | LastName | Age
在SectionName中需要插入Section->Name
需要插入部分Section->Index
在索引中需要插入Section->Item->Index
在插槽中需要插入Section->Item->Slot
等。
在MSSQL中我使用:
DECLARE @input XML = 'MY XML file'
select
Name = XCol.value('../@Index','varchar(25)'),
Cat = XCol.value('../@Name','varchar(25)'),
[Index] = XCol.value('@Index','varchar(25)'),
Slot = XCol.value('@Slot','varchar(25)')
from
@input.nodes('/ItemList/Section/Item') AS test(XCol)
非常感谢
答案 0 :(得分:0)
看here。看起来非常简单。在你的情况下,可能是这样的:
LOAD XML LOCAL INFILE 'some_file.xml'
INTO TABLE person
ROWS IDENTIFIED BY '<section>';