gpt4 book ai didi

java - 如何在通过 SAX Xerces 解析 XML 文档时引用 XSD 架构位置?

转载 作者:太空宇宙 更新时间:2023-11-04 09:00:08 24 4
gpt4 key购买 nike

如何在通过 SAX Xerces 解析 XML 时引用 XSD 架构位置?

< ?xml 版本=“1.0”编码=“ISO-8859-1”?> < com.firma xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

>  
< !-- xsi:noNamespaceSchemaLocation="F:\...\myschema_v2.5.xsd"

我必须在 XML 文档中真正引用这个元素吗???我希望不是... -->

我还在Java代码中设置如下,不太优雅,而且schema位置是固定的(不适合生产)
SaxParser.setProperty( “http://java.sun.com/xml/jaxp/properties/schemaSource”, “F:...\myschema_v2.5.xsd”);

最佳答案

将架构包含在您的 jar 中,并按以下方式使用 getResourceAsStream 加载它

reader.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", 
new InputSource(getClass().getResourceAsStream(xsdLocation)));

关于java - 如何在通过 SAX Xerces 解析 XML 文档时引用 XSD 架构位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/925180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com