使用无效的列名将XML导入mySQL?

时间:2013-07-12 19:22:09

标签: mysql xml database

我有这个XML文件,我试图导入到mySQL中。但是,使用LOAD XML查询不起作用,因为它们在变量名中是“ - ”。如何将其导入数据库并处理无效字符?:

    <?xml version="1.0" encoding="UTF-8"?>
<projects type="array">
  <project>
    <active type="boolean">true</active>
    <bill-by>none</bill-by>
    <billable type="boolean">true</billable>
    <budget type="decimal" nil="true"/>
    <budget-by>none</budget-by>
    <client-id type="integer">999</client-id>
    <code></code>
    <cost-budget type="decimal" nil="true"/>
    <cost-budget-include-expenses type="boolean">false</cost-budget-include-expenses>
    <created-at type="datetime">2013-06-27T18:10:26Z</created-at>
    <fees type="decimal" nil="true"/>
    <highrise-deal-id type="integer" nil="true"/>
    <hourly-rate type="decimal" nil="true"/>
    <id type="integer">38125</id>
    <name>Banking</name>
    <notify-when-over-budget type="boolean">false</notify-when-over-budget>
    <over-budget-notification-percentage type="decimal">80.0</over-budget-notification-percentage>
    <over-budget-notified-at type="date" nil="true"/>
    <show-budget-to-all type="boolean">false</show-budget-to-all>
    <updated-at type="datetime">2013-06-27T18:13:10Z</updated-at>
    <estimate nil="true"/>
    <estimate-by>none</estimate-by>
    <notes></notes>
    <hint-earliest-record-at type="NilClass">2013-06-24</hint-earliest-record-at>
    <hint-latest-record-at type="NilClass">2013-06-30</hint-latest-record-at>
    <hint-earliest-record-at>2013-06-24</hint-earliest-record-at>
    <hint-latest-record-at>2013-06-30</hint-latest-record-at>
  </project>

2 个答案:

答案 0 :(得分:0)

您必须在XML文件中修复字段名称。

此外,您还有另一个XML文件问题:<hint-earliest-record-at><hint-latest-record-at>出现两次,因此您必须选择一个删除或重命名。

我尝试了一个实验:

  1. 创建一个包含不包含短划线的列的表。
  2. 针对该表创建可更新的VIEW,使用短划线字符
  3. 定义视图的列名称
  4. 将XML加载到VIEW中,希望它插入到基表的相应列中。
  5. 但是这没用。它插入了一行,但所有值都插入为NULL。

    我还测试了创建具有普通列名的VIEW,没有破折号,然后我在XML中编辑了字段名称。通过VIEW加载此XML工作,并将行插入基表。所以我知道LOAD XML适用于可更新的VIEW。

答案 1 :(得分:0)

你可以使用 {“提示的最早记录在”}

通过这种方式,您可以使用连字符解析xml节点。

相关问题