2013-03-01 1 views
1

고객 클래스와 그에 관련된 xml 파일이 있습니다.Jaxb Unmarshaller에 문자열 형태로 XMl 전달하기

  File file = new File("D:\\TestingData\\customer.xml"); 
     JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class); 
     Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); 
     Customer data = (Customer) jaxbUnmarshaller.unmarshal(file); 

외부 위치에 customer.xml 파일을 배치해야합니다. (D : \ TestingData \ customer.xml)

제 질문은 XML의 일부로 XML 파일을 제공 할 수 있습니까?

답변

2

내가 문자열

네의 한 부분으로 XML 파일을 제공 할 수 있습니다, 당신은 단지 StringReader에 포장해야합니다.

String xml = "<foo><bar>Hello World</bar></foo>"; 
StringReader reader = new StringReader(xml); 
Foo foo = (Foo) unmarshaller.unnmarshal(reader); 
+1

덕분에 많은 도움이되었습니다. – Pawan