yli
yli

Reputation:

how to reference XSD Schema location while parsing XML Doc via SAX Xerces?

how to reference XSD Schema location while parsing XML via SAX Xerces?

< ?xml version="1.0" encoding="ISO-8859-1"?> < com.firma xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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

Must I reference this element really within the XML Doc??? I hope, not... -- >

I also set it as follows in Java code, which is not elegant, while schema location is fixed(not appropriate for production)
SaxParser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaSource", "F:...\myschema_v2.5.xsd" );

Upvotes: 1

Views: 2608

Answers (2)

yli
yli

Reputation:

I got it.

one must use as follows, giving "/com/firma/project/.../myschema_v2.5.xsd" as parameter. not forgetting the "/" in the path at the very beginning.

Upvotes: 0

Salandur
Salandur

Reputation: 6453

include the schema in your jar and load it using getResourceAsStream in the following way

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

Upvotes: 1

Related Questions