Hi Peter,

The URI of your schema is relative to the URI of the entity in which it is
referenced, in your case it's the document. So if your document's located
in 'C:\code\src\common\schemas', and you set the system ID on your
InputSource to 'file:///C:/code/src/common/schemas/request.xml', and you
set the schema location attribute to '../request.xsd', the parser will be
able to locate your schema.

You seem to be confusing Windows file names with URIs. The
noNamespaceSchemaLocation attribute expects a URI, also system IDs are
supposed to be specified as URIs (though the parser is sometimes lax on
that by default). 'c:\code\source\common\request.xsd' isn't a
valid URI, however 'file:///c:/code/source/common/request.xsd' is.

RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt?number=2396) describes the
URI syntax, if you're not familiar with it. Section 5.2 describes how
relative URIs are resolved against a base URI, if you're wondering how
that works.

-----------------------------------------
Michael Glavassevich
[EMAIL PROTECTED]
Candidate for Bachelor of Applied Science
Computer Engineering
University of Waterloo

On Tue, 3 Jun 2003, peter peter wrote:

> Hi Michael,
>               Thanks, it worked for me.
>               So it means schema should be relative to systemId path and it 
> cann't be the other way, that is if xml is in c:\code\src\common\schemas and 
> schema is in c:\code\src\common, then setting systemId will also not work, in 
> that case I have complete path of schema in the 
> xsi:noNamespaceSchemaLocation="c:\code\source\common\request.xsd"
>
> Can I buy this?
>
> Thanks once again.
>
> Regards,
> Peter
>
> Michael Rafael Glavassevich <[EMAIL PROTECTED]> wrote:
> Hi Peter,
>
> '/common/schemas/request.xsd' is a relative URI, but the leading slash,
> makes the path absolute so it won't be resolved against the base path. If
> your XML document is located in c:\code\source\common, then your schema
> location should be 'schemas/request.xsd', and if you're setting the system
> ID on your InputSource, it should be 'file:///c:/code/source/common/' for
> this example.
>
> Hope that helps.
>
> -----------------------------------------
> Michael Glavassevich
> [EMAIL PROTECTED]
> Candidate for Bachelor of Applied Science
> Computer Engineering
> University of Waterloo
>
> On Tue, 3 Jun 2003, peter peter wrote:
>
> > Hi All,
> > I am reading xml,schema from a jar file, and trying the validate the xml 
> > with the schema, If I give complete path in the 
> > xsi:noNamespaceSchemaLocation, it works fine, but if I give the relative 
> > path, it doesn't. I tried by setting the setSystemId as well, but in vain.
> >
> > Is there any way that without giving the complete path in 
> > xsi:noNamespaceSchemaLocation, it can be made to work?
> >
> > Some sample code-->
> >
> > String parserName = "org.apache.xerces.parsers.SAXParser";
> > XMLReader parser = XMLReaderFactory.createXMLReader(parserName);
> > parser.setFeature("http://xml.org/sax/features/validation";, true);
> > parser.setFeature("http://xml.org/sax/features/namespaces";, true);
> > parser.setFeature( "http://apache.org/xml/features/validation/schema",true 
> > );
> > ErrorHandler defaultHandler = new SAXErrorHandler();
> > parser.setErrorHandler(defaultHandler);
> >
> > InputSource source = new 
> > InputSource(this.getClass().getResourceAsStream("/common/request.xml"));
> >
> > parser.parse(source);
> >
> > XML is in directory c:\code\src\common
> >
> > ...
> >
> > Schema request.xsd is in directory c:\code\src\common\schemas
> >
> > Any help will be greatly appreciated...
> >
> > Regards,
> > Peter
> >
> >
> > ---------------------------------
> > Do you Yahoo!?
> > The New Yahoo! Search - Faster. Easier. Bingo.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
> ---------------------------------
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to