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 6239205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:21:09+00:00 2026-05-24T11:21:09+00:00

I have two xsd files to validate a xml. But the problem is my

  • 0

I have two xsd files to validate a xml. But the problem is my code takes only one xsd. How to use other xsd in the following code? I dont have idea about where should i place/call 2nd xsd file.

             private void validate(File xmlF,File xsd1,File xsd2) {
                    try {
                        url = new URL(xsd.toURI().toString());//  xsd1
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    }


                    source = new StreamSource(xml); // xml
                    try {
                        System.out.println(url);
                        schema = schemaFactory.newSchema(url);
                    } catch (SAXException e) {
                        e.printStackTrace();
                    }
                    validator = schema.newValidator();
                    System.out.println(xml);
                    try {
                        validator.validate(source);
                    } catch (SAXException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
  • 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-24T11:21:11+00:00Added an answer on May 24, 2026 at 11:21 am

    Plenty of hits when searching on SO or Google. One of them is this question, where the author found his own solution and reports the following code to add multiple xsd’s to the validator:

    Schema schema = factory().newSchema(new Source[] {
      new StreamSource(stream("foo.xsd")),
      new StreamSource(stream("Alpha.xsd")),
      new StreamSource(stream("Mercury.xsd")),
    });
    

    However, when working directly with InputStream on StreamSource, the resolver is not able to load any referenced XSD files. If, for instance, the file xsd1 imports or includes a third file (which is not xsd2), schema creation will fail. You should either set the system identifier (setSystemId) or (even better) use the StreamSource(File f) constructor.

    Adjusted to your example code:

    try {
      schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      schema = schemaFactory.newSchema(new Source[] {
        new StreamSource(xsd1), new StreamSource(xsd2)
      });
    } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    

    Note:

    If working with classpath resources, I’d prefer the StreamSource(String systemId) constructor (rather than creating a File):

    new StreamSource(getClass().getClassLoader().getResource("a.xsd").toExternalForm());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two xml files and I need to create one xsd for both.
I have two XML files with two different XSD schemas and different namespaces. They
I have two schema files one is imported from the other. When executing the
Here's my problem: I have two .xsd files, let's call them a.xsd and b.xsd.
I have two applications written in Java that communicate with each other using XML
I have two files, one with webservice description (wsdl), second with data structures used
I have created two wsdl files with shared types imported from xsd schema file.
We have to compare responses (XML) of two different but they are doing the
I have an XML document containing types from 2 XML schemas. One (theirs.xsd) is
I have two XML Schemas. First ( A.xsd ) is located in a library

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.