How to specify file on local disk with external schema

Discussion in 'XML' started by pohmart@yahoo.com, Mar 11, 2005.

  1. Guest

    I am using Xerces 2.6.2 and SAX on Windows2k. I want to validate an XML
    doc, which has no schema reference,
    with an external schema which is on my PC.

    I am setting the following properties and features:
    saxParser.setFeature("http://xml.org/sax/features/namespaces", true);
    saxParser.setFeature("http://xml.org/sax/features/namespace-prefixes",
    true);
    saxParser.setFeature("http://xml.org/sax/features/validation", true);
    saxParser.setFeature("http://apache.org/xml/features/validation/schema",
    true);
    saxParser.setFeature("http://apache.org/xml/features/standard-uri-conformant",
    false);
    saxParser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",

    "file:///C:/test/testSchema.xsd");

    When I parse the document the parser is unable to locate the schema
    document.
    I have tried several variations for the URL to the schema file such as:
    file://localhost/C:/test/testSchema.xsd
    C:/test/testSchema.xsd
    file:///C|/test/testSchema.xsd

    but nothing works.
    Can anyone tell me the correct way to do this?
    Thanks in advance,
    Paul
    , Mar 11, 2005
    #1
    1. Advertising

  2. Romin Guest

    In your last statement, you have mentioned:

    saxParser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
    "file:///C:/test/testSchema.xsd");

    which is not correct. You need to specify the second parameter
    as "TARGETNAMESPACE SCHEMAFILELOCATION"

    So, your TARGETNAMESPACE=http://mydomain.com/ns
    and your SCHEMAFILELOCATION=file:///c:/test/testSchema.xsd

    So -- your last statement should be:
    saxParser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
    "http://mydomain.com/ns file:///C:/test/testSchema.xsd");

    You should be able to get your targetnamespace value from the XSD file
    that you have.

    Hope this helps...
    Romin.


    wrote:
    > I am using Xerces 2.6.2 and SAX on Windows2k. I want to validate an

    XML
    > doc, which has no schema reference,
    > with an external schema which is on my PC.
    >
    > I am setting the following properties and features:
    > saxParser.setFeature("http://xml.org/sax/features/namespaces", true);
    >

    saxParser.setFeature("http://xml.org/sax/features/namespace-prefixes",
    > true);
    > saxParser.setFeature("http://xml.org/sax/features/validation", true);
    >

    saxParser.setFeature("http://apache.org/xml/features/validation/schema",
    > true);
    >

    saxParser.setFeature("http://apache.org/xml/features/standard-uri-conformant",
    > false);
    >

    saxParser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
    >
    > "file:///C:/test/testSchema.xsd");
    >
    > When I parse the document the parser is unable to locate the schema
    > document.
    > I have tried several variations for the URL to the schema file such

    as:
    > file://localhost/C:/test/testSchema.xsd
    > C:/test/testSchema.xsd
    > file:///C|/test/testSchema.xsd
    >
    > but nothing works.
    > Can anyone tell me the correct way to do this?
    > Thanks in advance,
    > Paul
    Romin, Mar 15, 2005
    #2
    1. Advertising

  3. Guest

    Romin,
    That did it. Thank you so much for both taking time out to reply and
    for the wonderfull clarity. It helped enormously!
    Paul
    , Mar 17, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jas Shultz
    Replies:
    0
    Views:
    942
    Jas Shultz
    Dec 3, 2003
  2. Markus
    Replies:
    1
    Views:
    1,522
    Markus
    Nov 23, 2005
  3. Till Soerensen
    Replies:
    1
    Views:
    1,219
    Henry S. Thompson
    Jun 9, 2004
  4. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,245
    Stanimir Stamenkov
    Apr 25, 2005
  5. Replies:
    12
    Views:
    518
    santosh
    Nov 15, 2006
Loading...

Share This Page