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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:28:02+00:00 2026-05-27T09:28:02+00:00

I am trying to build my first XML schema validator as a reusable component

  • 0

I am trying to build my first XML schema validator as a reusable component throughout my codebase and many projects. I have spent all day trying to follow examples and coding them up, and now have a proof of concept up and running.

The only problem is, its giving me false positives: its validating XML instances that should absolutely be failing. I’ve tested it out on 3 schemas: 1 schema it worked beautifully with, and now its misbehaving with the last two (false positives). I believe its because the first schema/instance pair I tried were extremely simple. I’m now trying to use it on more complex examples and it is choking.

Here is the body of the validate method where the SAX validation is done:

schema = getSchemaAsString();
targetXml = "ijeioj489fu4u8";

SAXParserFactory oSAXParserFactory = SAXParserFactory.newInstance();
SAXParser oSAXParser = null;
oSAXParserFactory.setNamespaceAware(true);

try 
{
    SchemaFactory oSchemaFactory =      
    SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 
    oSAXParserFactory.setSchema(oSchemaFactory.newSchema(new SAXSource(new InputSource(new StringReader(schema)))));

    oSAXParser = oSAXParserFactory.newSAXParser();

    DefaultHandler handler = new DefaultHandler(); 

    oSAXParser.parse(new InputSource(new StringReader(targetXml)), handler);
}
catch(Exception oException) 
{
    throw oException;
}  

Where schema and targetXml are in-memory XML strings (not file URIs) that are given the following values:

schema String:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="PayloadMessage">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="MessageID" type="xs:long"/>
            <xs:element name="Timestamp" type="xs:long"/>
            <xs:element name="MessageAction" type="xs:string"/>
            <xs:element name="ContentType" type="xs:string"/>
            <xs:element name="ContentID" type="xs:string"/>
            <xs:element name="Payload" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Obviously, the given targetXml should fail against its given schema. Nope. No exceptions get thrown anywhere inside the SAX stuff.

I have a feeling I need to do something with the DefaultHandler but not sure… I went to http://www.w3.org/2001/03/webdata/xsv and confirmed that my schema is valid.

Does anything jump out at anyone? Thanks in advance!

  • 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-27T09:28:03+00:00Added an answer on May 27, 2026 at 9:28 am

    You must set an error handler that will throw SAXException. The default behavior is to attempt parse document even if it isn’t valid. DefaultHandler implements ErrorHandler but the implementation in case of error or warning does nothing.

    Javadoc WARNING: If an application does not register an ErrorHandler, XML parsing errors will go unreported, except that SAXParseExceptions will be thrown for fatal errors. In order to detect validity errors, an ErrorHandler that does something with error() calls must be registered.

    I recommed this excellent tutorial with examples on XML validation. It was most helpful for me.

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

Sidebar

Related Questions

I'm trying to build my first generic list and have run into some problems.
I have a build.xml to use with ant, and I'm trying to put a
I'm trying to build my first cocoa application. done some iPhone developing before. I
I am trying to build my first CRUD application and cant get the update
Im trying to build a simple XML to Controls parser in my CF application.
I'm writing, or trying to write, Baby's First MDB on WebSphere 7. I have
I'm trying to build my first WP7 app and I'm a bit confused about
Today I've installed Bada SDK and trying first time to build some apps on
I'm trying build a method which returns the shortest path from one node to
Trying to build a GUI application in Java/Swing. I'm mainly used to painting GUIs

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.