2016-07-29 3 views
0

디스크에서 읽은 Simple XMl 파일을 구문 분석하고이를 JSON으로 변환하고 Mulesoft를 사용하여 파일에 다시 저장하려고합니다. 노새 flow.xml, 난 점점 오전 내가 노새 프로젝트를 실행하면mulesoft를 사용하여 XML 파일 구문 분석

<Names> 
    <Name> 
     <title>bnbnbha</title> 
     <firstname>aa</firstname> 
     <lastname>aaa</lastname> 
    </Name> 
    <Name> 
     <title>bjkjkjk</title> 
     <firstname>bb</firstname> 
     <lastname>bbb</lastname> 
    </Name> 
    <Name> 
     <title>hjhjhc</title> 
     <firstname>cc</firstname> 
     <lastname>ccc</lastname> 
    </Name> 
    <Name> 
     <title>djkjkj</title> 
     <firstname>dd</firstname> 
     <lastname>ddd</lastname> 
    </Name> 
</Names> 

같은 모습을 구문 분석하려고

<file:connector name="File" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/> 
    <file:connector name="File1" outputPattern="sample1.txt" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/> 
    <flow name="datatranformerFlow"> 
     <file:inbound-endpoint path="C:\Madhu" name="sample.xml" responseTimeout="10000" doc:name="File" connector-ref="File"/> 
     <file:file-to-string-transformer mimeType="application/xml" doc:name="File to String"/> 
     <splitter expression="#[xpath3('/Names/Name')]" doc:name="Splitter"/> 
     <json:xml-to-json-transformer doc:name="XML to JSON"/> 
     <file:outbound-endpoint path="C:\Madhu\GV dev documents\WD files" connector-ref="File1" responseTimeout="10000" doc:name="File"/> 
    </flow> 

샘플 XML 파일과 같은 방법

입니다 예외 :

INFO 2016-07-29 11 : 56 : 25,287 [[datatranformer] .File.receiver.01] org.mule.transport.file.FileMessageReceiver : 파일 : C : \ Madhu \ sample에서 획득 한 잠금. xxxx INFO 2016-07-29 11 : 56 : 26,193 [datatranformer] .datatranformerFlow.stage1.02] org.mule.routing.ExpressionSplitter : 표현식이 분할 될 수있는 유형으로 평가되지 않습니다. java.lang.String 오류 : '예기치 않은 문자'b '(코드 98)가 프롤로그에 있습니다. 예상 '<' [행, 열 {unknown-source}] : [2,3] ' 오류 2016-07-29 11 : 56 : 26,272 [[datatranformer] .datatranformerFlow.stage1.02] org.mule. exception.DefaultMessagingExceptionStrategy :


메시지 : com.ctc.wstx.exc.WstxUnexpectedCharException : 프롤로그 예기치 문자 'B'(번호 98); 에서 '<' 예상 [행, COL {알 수없는 소스}] : [2,3] (javax.xml.transform.TransformerException) 페이로드 : bnbnbha AA AAA

내가 뭐하는 거지 뭔가가 있나요 잘못된 ?

답변

0

당신은 단지 다음 제거 # [xpath3 ('/ 이름')]

1

목적은 XML 파일을 읽는 경우, JSON으로 변환하고, (자세한 과정없이)는 파일에 저장을 사용할 수 있습니다 문자열로 파일 변압기 및 분배기 흐름 제어.

그래서 당신은이처럼 될 구성 :

<flow name="datatranformerFlow"> 
    <file:inbound-endpoint path="C:\Madhu" name="sample.xml" responseTimeout="10000" doc:name="File" connector-ref="File"/> 
    <json:xml-to-json-transformer doc:name="XML to JSON"/> 
    <file:outbound-endpoint path="C:\Madhu\GV dev documents\WD files" connector-ref="File1" responseTimeout="10000" doc:name="File"/> 
</flow> 
+0

이을에 JSON하여 작업을 수행 할 수 있습니다 메시지 구성 요소

  • 을 변환 할 수
  • 하나 작품 .. 감사합니다 Logged –

    0

    그냥, 스플리터 식을 제거 방금 CSV로이 파일을 변환 할 언급 한 바와 같이, 아래의 흐름을 확인하십시오 :

    <?xml version="1.0" encoding="UTF-8"?> 
     
    
     
    <mule xmlns:json="http://www.mulesoft.org/schema/mule/json" 
     
    \t 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" 
     
    \t xmlns:spring="http://www.springframework.org/schema/beans" 
     
    \t xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     
    \t xsi:schemaLocation="http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.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 
     
    http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd"> 
     
        <file:connector name="File" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/> 
     
        <file:connector name="File1" outputPattern="sample1.txt" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/> 
     
        <flow name="datatranformerFlow"> 
     
         <file:inbound-endpoint path="C:\madhu" connector-ref="File" responseTimeout="10000" doc:name="File"/> 
     
         <file:file-to-string-transformer doc:name="File to String"/> 
     
         <json:xml-to-json-transformer mimeType="application/json" doc:name="XML to JSON"/> 
     
         <logger message="payload--&gt; #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/> 
     
        <file:outbound-endpoint path="C:\Madhu\GV dev documents\WD files" connector-ref="File1" responseTimeout="10000" doc:name="File"/> 
     
        </flow> 
     
    </mule>

    희망이 있습니다.

    0

    1. 당신의 XPath를 사용할 수있는 일을 여러 가지 방법이 있습니다 당신이에 의해 당신이 XML 변환