简体   繁体   English

如何读取xml文件并将其插入Mule中的数据库

[英]How to read xml file and insert it into Database in Mule

I have an xml file :- 我有一个xml文件:-

< getData >
< Data >
< id >321< /id >
< name >aa< /name >
< age >23< /age >
< designation >gfgf< /designation >
< /Data >
< /getData >

Where ID and AGE are integers ..... Now I want to insert these attributes of xml in Database using Mule... My Mule flow is :- 其中IDAGE是整数.....现在我想使用Mule在数据库中插入xml的这些属性...我的Mule流是:-

 < context:property-placeholder location="classpath:conf/DBConnectionProp.properties"/>
    < spring:beans>
        < spring:bean id="DB_Source" name="DB_Source" class="org.enhydra.jdbc.standard.StandardDataSource">
            < spring:property name="url" value="${url}"/>
            < spring:property name="driverName" value="${driverName}"/>
        </spring:bean>
    < /spring:beans>
    < jdbc-ee:connector name="Database-Connector" dataSource-ref="DB_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"> 

 < jdbc-ee:query key="InsertQuery" value="INSERT INTO &quot;getData&quot;(ID,NAME,AGE,DESIGNATION)VALUES (#[xpath('//id').text],#[xpath('//name').text],#[xpath('//age').text],#[xpath('//designation').text])"></jdbc-ee:query>  
    < /jdbc-ee:connector>

     <file:connector name="File_Input" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/>
     <flow name="testxmlFlow1" doc:name="testxmlFlow1"> 
        < file:inbound-endpoint path="E:\backup\test" responseTimeout="10000" doc:name="File" moveToPattern="Input.xml" connector-ref="File_Input"></file:inbound-endpoint>  
        < byte-array-to-string-transformer doc:name="Byte-Array-to-String" >< /byte-array-to-string-transformer >  
        < splitter evaluator="xpath" expression="/getData/Data" doc:name="Splitter" >< /splitter >  
        < jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="InsertQuery" queryTimeout="-1" connector-ref="Database-Connector" doc:name="Database"></jdbc-ee:outbound-endpoint >  
    < /flow >

Please help ..... I am getting following exception :- 请帮助.....我收到以下异常:-

Root Exception stack trace:
org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 2; The markup in the document following the root element must be well-formed.
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1236)
    at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:485)
    at org.mule.module.xml.transformer.XmlToDomDocument.transformMessage(XmlToDomDocument.java:63)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

how can I insert the values in which ID and Age are Int ???? 如何插入ID和Age为Int的值?

It's now working .... Actually I have to add 它现在正在工作....实际上我必须添加
<file:filename-regex-filter pattern="Input.xml" caseSensitive="false"/> ... and it's running fine and picking up only "Input.xml " and thus no exception now ... earlier it was picking all the files in the folder and thus that exception raised <file:filename-regex-filter pattern="Input.xml" caseSensitive="false"/> ...并且它运行良好,仅拾取了“ Input.xml”,因此现在也没有异常...文件夹中的所有文件,因此引发异常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM