使用Mule ESB,Mule Studio将数据插入PostgreSQL时无法从XML中正确读取数据

时间:2012-12-18 14:31:17

标签: mule mule-studio

我有一个xml文件,如

<Families>
    <Family>
        <title>Mr</title>
        <name>Xyz</name>    
    </Family>
    <Family>
        <title>Mr</title>
        <name>Mno</name>    
    </Family>
</Families>

我正在尝试读取文件并将数据存储到PostgreSQL数据库中。我的配置xml文件在

下面
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd 
http://www.mulesoft.org/schema/mule/jdbc http://www.mulesoft.org/schema/mule/jdbc/current/mule-jdbc.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
    <jdbc:postgresql-data-source name="PostgreSQL_Data_Source" user="superuser" password="pwd" url="jdbc:postgresql://localhost:5432/TestDB" transactionIsolation="UNSPECIFIED" doc:name="PostgreSQL Data Source"/>
    <jdbc:connector name="Database-Connector" dataSource-ref="PostgreSQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database">
        <jdbc:query key="InsertQuery" value="INSERT INTO &quot;tblTest&quot;(title, content)VALUES (#xpath://title,#xpath://name)"/>
    </jdbc:connector>
    <flow name="testxmlFlow1" doc:name="testxmlFlow1">
        <file:inbound-endpoint path="C:\Users\nbiswas\Documents\InputFolder" responseTimeout="10000" doc:name="File"/>
        <byte-array-to-string-transformer doc:name="Byte-Array-to-String"/>
        <splitter evaluator="xpath" expression="/Families/Family" doc:name="Splitter"/>
        <jdbc:outbound-endpoint exchange-pattern="one-way" queryKey="InsertQuery" queryTimeout="-1" connector-ref="Database-Connector" doc:name="Database"/>
    </flow>
</mule>

在运行时,我收到以下错误(主要是)

Exception stack is:
1. ERROR: syntax error at or near ":"
  Position: 52(SQL Code: 0, SQL State: + 42601) (org.postgresql.util.PSQLException)
  org.postgresql.core.v3.QueryExecutorImpl:2157 (null)
2. ERROR: syntax error at or near ":"
  Position: 52 Query: INSERT INTO "tblTest"(title, name)VALUES (#xpath://title,#xpath://name) Parameters: [](SQL Code: 0, SQL State: + 42601) (java.sql.SQLException)
  org.apache.commons.dbutils.QueryRunner:540 (null)

我怀疑

中有错误

“VALUES(#xpath:// title,#xpath:// name)”

有人可以帮助我解决问题吗?

提前致谢

1 个答案:

答案 0 :(得分:1)

这不是有效的表达式语言语法,类似于#[ ... ],也不是有效的MEL XPath表达式(请参阅http://www.mulesoft.org/documentation/display/MULE3USER/Mule+Expression+Language#MuleExpressionLanguage-Xpath)。

使用:#[xpath('//title').text]

请注意,我添加了.text,因为您需要所选DOM元素的文本内容,而不是DOM元素本身。