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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:24:41+00:00 2026-05-17T16:24:41+00:00

I’m trying to put together some validation code. I am trying to validate against

  • 0

I’m trying to put together some validation code. I am trying to validate against a schema like:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:choice="http://example.com/SimpleChoice" targetNamespace="http://example.com/SimpleChoice" ecore:nsPrefix="choice" ecore:package="com.example.simple.choice">
    <xsd:complexType name="Plane">
        <xsd:sequence>
            <xsd:element name="freightDetails" type="xsd:string" minOccurs="0"/>
            <xsd:element name="passengers" type="xsd:int" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

With the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<choice:Plane xmlns:choice="http://example.com/SimpleChoice">
    <freightDetails>Boxes</freightDetails>
</choice:Plane>

It seems to complain that there is no element, but I’m trying to find a way to validate against the type. I get the following error:

[Error] :1:100: cvc-elt.1: Cannot find the declaration of element 'choice:Plane'.

When it tries to load the document with the following code:

SchemaFactory factory =
    SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(schemaFile);

DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
parserFactory.setSchema(schema);
parserFactory.setNamespaceAware(true);
DocumentBuilder parser = parserFactory.newDocumentBuilder();

Document document = parser.parse(inputSource);

Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));

It fails when it gets to the:

Document document = parser.parse(inputSource);

Does anyone have any ideas on how I would be able to get this working? (Or a validator that supports this sort of behaviour?)

Thanks

Rob

  • 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-17T16:24:42+00:00Added an answer on May 17, 2026 at 4:24 pm

    This is because your schema has defined a type (Plane), but hasn’t defined any permitted elements that use that type. A type on its own has no meaning outside of the schema itself.

    You need to add an <xsd:element> to your schema. The simplest solution is to use an anonymous complex type within that, something like:

    <xsd:element name="Plane">
      <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="freightDetails" type="xsd:string" minOccurs="0"/>
            <xsd:element name="passengers" type="xsd:int" minOccurs="0"/>
        </xsd:sequence>
      </xsd:complexType>    
    </xsd:element>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.