这是我第一次在这里寻求帮助,我希望有人能帮助我。
我接到的任务是本地化我们的 ant 构建过程,以帮助减少构建时间。
这个想法类似于构建一个 Ant 任务来下载与特定服务关联的 WSDL 并将其保存在本地。长话短说,这已经完成,但由于某种原因,当使用本地文件构建服务时,我在第一个导入的 XSD 中收到“序言中不允许内容”错误。
我搜索过论坛,最常见的 react 是序言之前的隐藏字符,但我检查了十六进制代码,没有隐藏字符。
这是 WSDL 序言
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
这是第一个 XSD 序言
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
十六进制序言
3C3F786D6C2076657273696F6E3D2231
2E302220656E636F64696E673D227574
662D3822207374616E64616C6F6E653D
226E6F223F3E
与远程版本相同。
这也是下载的 XSD 和 WSDL 的保存方式。
private Document convertToXML(String xmlSource) throws Exception {
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(xmlSource)));
return document;
}
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
Result output = new StreamResult(new File(filePath));
请告诉我是否应该更具体或是否需要添加更多信息。
谢谢。
最佳答案
问题出在我正在更改的 WSDL 中。
原始 WSDL
<xsd:import namespace="http://someNameSpace"
schemaLocation="http://someLocation/dir1/dir2/schema.xsd"/>
有问题的 WSDL
<xsd:import namespace="http://someNameSpace"
schemaLocation="dir1/dir2/schema.xsd"/>
工作 WSDL
<xsd:import namespace="http://someNameSpace"
schemaLocation="schema.xsd"/>
现在 WSDL 和 XSD 都位于同一目录中,没有子目录。
关于java - 保存下载的 XSD 和 WSDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17950464/