Scriptella: XML to DB: Insert Into from XPATH

痴心易碎 提交于 2019-12-24 12:16:29

问题


I have an XML file that looks like this:

<XML>
  <Table name='test'>
    <Row>
      <Field name='key'>1000</Field>
      <Field name='text'>Test</Field>
    </Row>
  </Table>
</XML>

id like to parse this xml and use it within an insert statement:

<query  connection-id="in">
    /XML/Table/Row

    <script connection-id="out">
        INSERT INTO X t (
                t.entitykey, 
                t.text
             )
             VALUES 
             (
                 ????????
             );

    </script>
</query>

How do I access a specific Field-Tag from within the insert statement using XPATH? We prefer to have one XSD that takes all table layouts into account and not to maintain n xsd for each table hence the Field[@name] design.

Thanks Matthias


回答1:


Xpath driver exposes a variable called node which provides a context for executing xpath expressions over a currently returned node. You can use the following expression to get the value of a particular field:

<script connection-id="out">
    INSERT INTO X t (t.entitykey, t.text)
         VALUES ( ?{node.getString("./Field[@name = 'text']")} );
</script>


来源:https://stackoverflow.com/questions/21486352/scriptella-xml-to-db-insert-into-from-xpath

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!