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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:14:23+00:00 2026-05-25T19:14:23+00:00

I am having trouble validating an XML using an XSD via code. I can’t

  • 0

I am having trouble validating an XML using an XSD via code. I can’t figure out what I’m missing
XML:

<?xml version="1.0" encoding="UTF-8"?>
<systems xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns="test.namespace">
  <system address="test" id="test" name="test" systemNr="test">
    <mandant mandant="test"/>
  </system>
  <system address="test2" name="test2" systemNr="test2" id="test2">
    <mandant mandant="test2"/>
    <mandant mandant="test2"/>
  </system>
  <system id="test3" address="test3" name="test3" systemNr="test3">
    <mandant mandant="test"/>
  </system>
</systems>

XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="test.namespace">
  <xs:element name="systems">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="system" maxOccurs="unbounded" minOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="mandant"
                maxOccurs="unbounded" minOccurs="1">
                <xs:complexType>
                  <xs:attribute name="mandant"
                    type="xs:string" use="required">
                  </xs:attribute>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="id" type="xs:string" use="required">
            </xs:attribute>
            <xs:attribute name="name" type="xs:string" use="required">
            </xs:attribute>
            <xs:attribute name="address" type="xs:string" use="required">
            </xs:attribute>
            <xs:attribute name="systemNr"
              type="xs:string" use="required">
            </xs:attribute>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

And here is the code snippet:

      File systemsFile = new File(LocalFileSystemManager.getDefaultPath() + "Systems.xml");
      File schemaFile = new File(LocalFileSystemManager.getDefaultPath() + "SystemsSchema.xsd");
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document systemsDocument = db.parse(systemsFile);
      systemsDocument.getDocumentElement().normalize();
SchemaFactory factory = SchemaFactory
      .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      Schema schema = factory.newSchema(schemaFile);
      Validator validator = schema.newValidator();
      validator.validate(new DOMSource(systemsDocument));

Thanks in advance!
Lori

  • 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-25T19:14:23+00:00Added an answer on May 25, 2026 at 7:14 pm

    This instance should validate. Your attributes belong to the schema so you need to mark them as such with a namespace:

    <?xml version="1.0" encoding="UTF-8"?>
    <systems xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns="test.namespace">
       <system a:address="test" a:id="test" a:name="test" a:systemNr="test" xmlns:a="test.namespace">
          <mandant a:mandant="test"/>
       </system>
       ...
    </systems>
    

    I am assuming you have attributeFormDefault="qualified" and elementFormDefault="qualified" in your <schema /> element?

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

Sidebar

Related Questions

I'm having trouble finding out the schema location from the XML using the xstream
I am having trouble validating my xml schema. I get these errors on the
I'll admit, I'm an XML newbie. I'm having trouble validating some xml against a
I am having trouble validating serialized data. Ok, so I started with an XSD
I've been rebuilding my site with code igniter and am having trouble validating the
I having some trouble trying to figure out how to implement a Rails 3
I am having trouble using the StringLengthAttribute when validating my model using Entity Framework
Having trouble linking the Stomp.framework into an iPhone SDK application. http://code.google.com/p/stompframework/ I follow the
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
Im having trouble using a .NET COM in vb6, It compiles ok and I

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.