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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:23:32+00:00 2026-06-17T04:23:32+00:00

I would like to validate an XML file using a schema located at a

  • 0

I would like to validate an XML file using a schema located at a secure https site. How do I tell the validator to except a self-signed certificate or use an https URL? I have a file called test.xml and a schema located at https://localhost:1234/module/testschema.xsd. I’m using the same code found here. If I use a regular URL (http://localhost/module/testschema.xsd), it works great. If I substitute with an https URL, then I get this error:

schema_reference.4: Failed to read schema document ‘https://localhost:1234/module/testschema.xsd‘, because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

Copied Code:

public boolean validateFile(String xml, String strSchemaLocation)
{
Source xmlFile = null;
try {
    URL schemaFile = new URL(strSchemaLocation);
    xmlFile = new StreamSource(new File(xml));
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = schemaFactory.newSchema(schemaFile);
    Validator validator = schema.newValidator();
    validator.validate(xmlFile);
    System.out.println(xmlFile.getSystemId() + " is valid");
} catch (SAXException e) {
    System.out.println(xmlFile.getSystemId() + " is NOT valid");
    System.out.println("Reason: " + e.getLocalizedMessage());
    return false;
} catch (IOException ioe) {
    System.out.println("IOException");
    return false;
}

return true;
}
  • 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-06-17T04:23:33+00:00Added an answer on June 17, 2026 at 4:23 am

    This has very little to to do with schema validation. Your problem is that you need to establish an HTTPS connection and trust a self-signed certificate. See How can I use different certificates on specific connections? or google around for that.

    I don’t think you’ll be able to use the SchemaFactory.newSchema factory method that takes a File, so just use the one that takes a StreamSource:

    URL schemaFile = new URL(strSchemaLocation);
    HttpsURLConnection schemaConn = (HttpsURLConnection)schemaFile.openConnection();
    // Magic from the other answer to accept self-signed cert
    InputStream is = schemaConn.getInputStream();
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = schemaFactory.newSchema(new StreamSource(is));
    

    (I’m leaving out the try..catch to close the input stream and the connection)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to validate a XML file with a schema for that values
I am receiving this XML file which I would like to validate. Ideally I
I want to validate xml against xsd file. So I would like to install
I would like to validate and restrict newline/linefeed character. Valid XML: <root> <node>data data</node>
I would like to validate an email using the RegexValidator, e.g. [RegexValidator(@^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$)] Which works
I'm using jQuery Validate and would like to re-validate a group of fields whenever
I'm trying to use the XML::LibXML::Schema to validate a xml file against a xsd.
Is it possible to validate the following xml with the following schema? I'd like
I would like to validate the cXML Invoice against the DTD using Linq to
I'm trying to parse XML files and I would like to provide a schema

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.