Hi,
A first version of the LOAD XML is now available. It is based on the
LOAD DATA command, and has the following syntax:
LOAD XML [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'
[REPLACE | IGNORE]
INTO TABLE tbl_name
ROWS IDENTIFIED BY 'row_tag'
[IGNORE number LINES]
[(col_name_or_user_var,...)]
[SET col_name = expr,...)]
Basically this is the same syntax as LOAD DATA, and the xml import
also works the same way. The main difference is that the LINES and
FIELDS clauses are not supported.
Instead a ROWS IDENTIFIED BY clause is used. For every tag with this
tag name the command will try to create a record. It will match all
tags and attributes inside the row tag and all tags and attributes on a
higher level with the columns in the target table and fill in values
accordingly.
The command supports three different xml formats:
field values as attributes: “<row field1='value' field2='value2' />”
field values as tags:
<row><field1>value</field1><field2>value2</field2></row>
the format used by other MySQL tools, where the field name is an
attribute, and the value is in the tag:
<row><field name='field1'>value</field></row>
The three formats can be used in the same xml file, the import will
automatically detect them. The tags are matched based on tag/attribute
name and column name.
Changes are in attached patch file. Four files are affected:
lex.h (only add symbol XML_SYM)
sql_class.h (add enum_filetype and use in sql_exchange)
sql_yacc.yy (definition of command LOAD XML)
sql_load.cc(the implementation)
Erik Wetterberg
Attachment: [text/x-patch] loadxml.patch
Attachment: [text/x-patch]