我有一个这样的方法。
public void myMethod(String xml){
...
File file=convertStringToFile(xml) // I need to convert xml string to File
object.fileDemandingMethod(file);
}
fileDemandingMethod(file) 需要文件,但我的输入是字符串。
如何获取文件对象形式的 xml 字符串?
我需要这个来进行 JAXB 验证
Schema schema = schemaFactory.newSchema(new File("C:\\schema.xsd"));
unmarshaller.setSchema(schema );
最佳答案
由于您还可以使用 StreamSource
,因此您可以使用 String
构造一个 javax.xml.transform.Source
:
new StreamSource(new StringReader(xml))
关于java - 字符串到文件(JAXB 验证),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14806884/