0

I have an xml file as under

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

I am trying to read the file and store the data into PostgreSQL database. My configuration xml file is as under

<?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>

While running , I am receiving the below error (mainly)

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)

I am suspecting that there is something wrong in

"VALUES (#xpath://title,#xpath://name)"

Can someone help me out as what is wrong?

Thanks in advance

1 Answer 1

1

This is not a valid expression language syntax, which are like #[ ... ], nor a valid MEL XPath expression (see http://www.mulesoft.org/documentation/display/MULE3USER/Mule+Expression+Language#MuleExpressionLanguage-Xpath).

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

Note that I added .text because you want the text content of the selected DOM element, not the DOM element itself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.