Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6556763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:59:10+00:00 2026-05-25T12:59:10+00:00

i have a schema.xsd which includes and modifies xhtml like this: <xs:redefine schemaLocation=http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd> …

  • 0

i have a schema.xsd which includes and modifies xhtml like this:

<xs:redefine schemaLocation="http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd">
...
</xs:redefine>

Now i have written a Validator, which

  • reads the schema from xml file
  • uses a CatalogManager for resolving entities

it works fine as it does not load any files from the net but rather finds xhtml11.xsd as given in my catalog.xml file.

public class XmlTemplateValidator implements TemplateValidator
{
    public List<SAXParseException> validate ( String xml ) throws Exception
    {
        Reader input = new StringReader(xml);
        InputSource inputSource = new InputSource(input);

        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        SAXParser parser = factory.newSAXParser();
        parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
        XMLReader reader = parser.getXMLReader();
        reader.setEntityResolver(new CatalogResolver());
        DefaultErrorHandler handler = new DefaultErrorHandler();
        reader.setErrorHandler(handler);
        reader.parse(inputSource);
        return handler.getSaxParseExceptions();
    }

}

Now i want exactly the same thing, but i want to give the schema inside my validator (so not let the author say against which schema it should validate, but rather let the validator decide which schema to use.

public class NewXmlTemplateValidator implements TemplateValidator
{
    static final String schemaSource    = "schema.xsd";

    public List<SAXParseException> validate ( String xml ) throws Exception
    {
        Reader input = new StringReader(xml);
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        URL schemaUrl = getClass().getResource(schemaSource);
        Schema schema = factory.newSchema(schemaUrl);
        Validator validator = schema.newValidator();
        DefaultErrorHandler handler = new DefaultErrorHandler();
        validator.setErrorHandler(handler);
        Source source = new StreamSource(input);
        validator.validate(source);
        return handler.getSaxParseExceptions();
    }
}

It works but it does load all xhtml files form the net which takes rather long and is not what i want.

So i want to validate a XML String against a predefined schema with proper entity resolving via a catalog.xml definition.

How can i easily add a CatalogResolver to the second setup?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:59:11+00:00Added an answer on May 25, 2026 at 12:59 pm

    Add an XMLCatalogResolver in the second example like this:

    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    URL schemaUrl = getClass().getResource(schemaSource);
    String catalog = getClass().getResource("/catalog.xml").getFile();
    XMLCatalogResolver resolver = new XMLCatalogResolver(new String[] { catalog });
    factory.setResourceResolver(resolver);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an .xsd schema like this <?xml version=1.0 encoding=utf-8?> <xs:schema id=NewDataSet xmlns= xmlns:xs=http://www.w3.org/2001/XMLSchema
I have the following xml - <Surveys xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation=ImmForm XML Schema NHS Direct.xsd><Svy SurveyName=WeeklyFluSurveillance2012/13-NHSDirectWeek40w/e07/10/2012
I have xsd schema file which I can't change. Here is an excerpt that
I have an XSD which was transformed from a RELAX NG schema with a
I have this big doubt. When ever i use base64Binary in an .xsd schema
I have this xsd which is kind of bad, but I have to use
I have a an XSD schema which contains both xsd types and elements of
I have the following xml which has xsd schema, but is poor and no
I have an XSD (XML Schema) which contains multiple files. There's a catalog.xml in
I have a gigantic QuickBooks SDK .XSD schema file which defines XML requests/responses that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.