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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:54:43+00:00 2026-05-11T23:54:43+00:00

some code snippets. The java coding doing the jaxb unmarshaling. pretty straightforward, copied out

  • 0

some code snippets.

The java coding doing the jaxb unmarshaling. pretty straightforward, copied out of tutorials online.

JAXBContext jc = JAXBContext.newInstance( "xmlreadtest" );
Unmarshaller u = jc.createUnmarshaller();

// setting up for validation.
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
StreamSource schemaSource =  new StreamSource(ReadXml.class.getResource("level.xsd").getFile());
Schema schema = schemaFactory.newSchema(schemaSource);
u.setSchema(schema);

// parsing the xml
URL url = ReadXml.class.getResource("level.xml");
Source sourceRoot = (Source)u.unmarshal(url);

The problem element from the xml file. The element contains nothing but ignorable whitespace. Its badly formated as its shown exactly how its found in the file.

<HashLine _id='FI6'
ppLine='1'
origLine='1'
origFname='level.cpp'>
</HashLine>

The xsd element which described this element.

<xs:element name="HashLine">
  <xs:complexType>
    <xs:attribute name="origLine" type="xs:NMTOKEN" use="required" />
    <xs:attribute name="origFname" type="xs:string" use="required" />
    <xs:attribute name="_id" type="xs:ID" use="required" />
    <xs:attribute name="ppLine" type="xs:NMTOKEN" use="required" />
  </xs:complexType>
</xs:element>

the error is

[org.xml.sax.SAXParseException: cvc-complex-type.2.1: Element 'HashLine' must have no character or element information item [children], because the type's content type is empty.]

I’ve verified the error is coming from that element.

It loads fine with no validation. But I need to use validation as I’m going to be doing heavy changes and additions to the application, and I have to be certain everything gets marshaled/unmarshaled properly.

It also works fine if I change the complexType to include a simpleContext with an xs:string extension. But I’m getting this issue from entities all over, of which there are alot, amd in alot of xsd files. So its not feasible to base every element in the xml documents on xs:string just to get around this issue.

Event though j2se 6 is using the SchemaFactory from apache-xerces, it doesn’t seem to accept the ‘ignore-whitespace’ feature of from xerces. (i.e. schemaFactory.setFeature() )

  • 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-11T23:54:43+00:00Added an answer on May 11, 2026 at 11:54 pm

    You could use the StAX API to filter out empty character blocks prior to validation using an EventFilter:

    class WhitespaceFilter implements EventFilter {
      @Override
      public boolean accept(XMLEvent event) {
        return !(event.isCharacters() && ((Characters) event)
            .isWhiteSpace());
      }
    }
    

    This can be used to wrap your input:

    // strip unwanted whitespace
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLEventReader eventReader = inputFactory
        .createXMLEventReader(ReadXml.class.getResourceAsStream("level.xml"));
    eventReader = inputFactory.createFilteredReader(eventReader,
        new WhitespaceFilter());
    
    // parsing the xml
    Source sourceRoot = (Source) unmarshaller.unmarshal(eventReader);
    
    //TODO: proper error + stream handling
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 164k
  • Answers 164k
  • 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 I fail at VB, but in C# you would call… May 12, 2026 at 12:20 pm
  • Editorial Team
    Editorial Team added an answer This will match 6 to 15 characters (letters or digits),… May 12, 2026 at 12:20 pm
  • Editorial Team
    Editorial Team added an answer According to help cmd: If /D was NOT specified on… May 12, 2026 at 12:20 pm

Related Questions

Hi I'm pretty new to Stack Overflow so I hope that I'm doing this
I'm looking for a good tutorial on TCP socket programming in Java. The emphasis
Does anyone know of a good online compiler/runtime (for C++, Java, Python, ObjC etc.)
Let's say I have a java program that makes an HTTP request on a

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.