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

  • Home
  • SEARCH
  • 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 4027416
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:05:38+00:00 2026-05-20T11:05:38+00:00

This is my XML: <?xml version=1.0?> <root xmlns=http://example.com/first-schema.xsd xmlns:f=http://example.com/second-schema.xsd> <f:foo>test</f:foo> </root> Now I want

  • 0

This is my XML:

<?xml version="1.0"?>
<root xmlns="http://example.com/first-schema.xsd"
  xmlns:f="http://example.com/second-schema.xsd">
  <f:foo>test</f:foo>
</root>

Now I want to validate whether this XML is XMLSchema-valid. I don’t have these first-schema.xsd and second-schema.xsd files locally. Moreover, I don’t know anything about them. I just want to make sure that my XML document is valid against its schemas. Is it possible to do in Java?

  • 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-20T11:05:39+00:00Added an answer on May 20, 2026 at 11:05 am

    You can use the javax.xml.validation APIs for this.

    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 
    URL schemaURL = // The URL to your XML Schema; 
    Schema schema = sf.newSchema(schemaURL); 
    Validator validator = schema.newValidator();
    DOMSource source = new DOMSource(xmlDOM);
    validator.validate(source);
    

    The example below demonstrates how to validate a JAXB object model against a schema, but you’ll see it’s easy to replace the JAXBSource with a DOMSource for DOM:

    • http://bdoughan.blogspot.com/2010/11/validate-jaxb-object-model-with-xml.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this XML at http://localhost/file.xml : <?xml version=1.0 encoding=utf-8?> <val:Root xmlns:val=http://www.hw-group.com/XMLSchema/ste/values.xsd> <Agent> <Version>2.0.3</Version>
Considering this xml document: DECLARE @X XML (DOCUMENT search.SearchParameters) = '<parameters xmlns=http://www.educations.com/Search/Parameters.xsd xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> <parameter
I have the following XML example: <?xml version=1.0 encoding=UTF-8?> <OpenSearchDescription xmlns=http://a9.com/-/spec/opensearch/1.1/ xmlns:custom=http://example.com/opensearchextensions/1.0/> <ShortName>Test</ShortName> <Description>Testing....</Description>
My main.xml looks like this: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent >
Given this XML ... <ListBucketResult xmlns=http://s3.amazonaws.com/doc/2006-03-01/> <Name>public.rpmware.com</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> <Contents> <Key>0.dir</Key> <LastModified>2008-06-25T16:09:49.000Z</LastModified>
If I run this XML validation via xmllint: xmllint --noout --schema schema.xsd test.xml I
I've got some XML, for example purposes it looks like this: <root> <field1>test</field1> <f2>t2</f2>
I have the following (as an example) XML file and XSD. <?xml version=1.0 encoding=utf-8
There is a schema with the following boring root element: <?xml version=1.0 encoding=utf-8?> <xs:schema
I'm having issues with schema validation, this is my xml <?xml version=1.0 encoding=utf-8 ?>

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.