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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:46:48+00:00 2026-05-11T05:46:48+00:00

In Java, I can validate an XML document against an XSD schema using javax.xml.validation.Validator,

  • 0

In Java, I can validate an XML document against an XSD schema using javax.xml.validation.Validator, or against a DTD by simply parsing the document using org.xml.sax.XMLReader.

What I need though is a way of programmatically determining whether the document itself validates against a DTD (i.e. it contains a <!DOCTYPE ...> statement) or an XSD. Ideally I need to do this without loading the whole XML document into memory. Can anyone please help?

(Alternatively, if there’s a single way of validating an XML document in Java that works for both XSDs and DTDs – and allows for custom resolving of resources – that would be even better!)

Many thanks,

A

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T05:46:49+00:00Added an answer on May 11, 2026 at 5:46 am

    There is no 100% foolproof process for determining how to validate an arbitrary XML document.

    For example, this version 2.4 web application deployment descriptor specifies a W3 schema to validate the document:

    <?xml version='1.0' encoding='UTF-8'?> <web-app id='WebApp_ID' version='2.4'     xmlns='http://java.sun.com/xml/ns/j2ee'     xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'     xsi:schemaLocation='http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd'> 

    However, this is an equally valid way of expressing the same thing:

    <?xml version='1.0' encoding='UTF-8'?> <web-app id='WebApp_ID' version='2.4'     xmlns='http://java.sun.com/xml/ns/j2ee'> 

    RELAX NG doesn’t seem to have a mechanism that offers any hints in the document that you should use it. Validation mechanisms are determined by document consumers, not producers. If I’m not mistaken, this was one of the impetuses driving the switch from DTD to more modern validation mechanisms.

    In my opinion, your best bet is to tailor the mechanism detector to the set of document types you are processing, reading header information and interpreting it as appropriate. The StAX parser is good for this – because it is a pull mechanism, you can just read the start of the file and then quit parsing on the first element.

    Link to more of the same and sample code and whatnot.

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

Sidebar

Ask A Question

Stats

  • Questions 154k
  • Answers 154k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer try authorize.net. May 12, 2026 at 10:33 am
  • Editorial Team
    Editorial Team added an answer I came across the same problem, after deep investigation, I… May 12, 2026 at 10:33 am
  • Editorial Team
    Editorial Team added an answer You are sending data over POST, you don't need the… May 12, 2026 at 10:33 am

Related Questions

I was just wondering if someone could give my XML validation code a once
Among the data my application sends to a third-party SOA server are complex XMLs.
I Have following in my struts.xml file <action name=ProductVerification class=com.frontend.ProductVerification> <result name=success>/jsp/product_verification.jsp</result> <result name=input>/jsp/product_verification.jsp</result>
I'm coding an italian website where I need to validate some input data with

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.