0

我有一个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)

我怀疑有什么问题

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

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

提前致谢

4

1 回答 1

1

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

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

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

于 2012-12-18T16:49:12.310 回答