如何在通过 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)));
我是一名优秀的程序员,十分优秀!