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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:23:20+00:00 2026-05-22T16:23:20+00:00

I’ve been tasked with writing a parser for xml documents with a supporting schema

  • 0

I’ve been tasked with writing a parser for xml documents with a supporting schema that was created by people purportedly smarter and more experienced than I. I am no xml expert, however, from what I can tell, I believe there are some considerations missing from their schema.

Here’s a simplified version of the schema I’ve been given:

<?xml version="1.0"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xsd:attributeGroup name="Group1">
            <xsd:attribute name="attrib1" type="xsd:NMTOKENS"/>
            <xsd:attribute name="attrib2" type="xsd:NMTOKENS"/>
        </xsd:attributeGroup>
</xsd:schema>

Before I go back to my clients and criticize their schema design, I’d really appreciate the collective stackoverflow intellect to confirm or deny the following for me:

  1. An attributeGroup should be used by some sort of element within a schema. It does not make sense to just have an attributeGroup standing alone in a schema. (unless this schema is intended to be imported into another)
  2. An attribute within an attributeGroup can only occur once within a single element of a valid xml document. for example:

    <?xml version="1.0"?>
    <element1 attrib1="first second third" attrib1="first second third"/>
    

    is not valid because there is a duplicate ‘attrib1’, correct?

    • I have been told that I may receive documents with duplicate attributes. I would like to tell my clients that the schema needs to reflect that possibility (if that’s even possible…). Is there a way to define an attribute which can occur more than once? I’m aware of the ‘maxOccurs’ attribute but I don’t believe that is valid for an attribute definition.

Thanks in advance for your input.

  • 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-22T16:23:21+00:00Added an answer on May 22, 2026 at 4:23 pm

    An attributeGroup should be used by
    some sort of element within a schema.
    It does not make sense to just have an
    attributeGroup standing alone in a
    schema.

    Well, it depends if it makes sense or not. In XML attributes are like “extra information attached to an element”. So in the instance document an attribute cannot exist without an element that “hosts” it. To have an attribute in the instance document requires that 1) there is an element that has this attribute 2) this attribute is somehow defined or referenced in the schema. If no element in the schema is defined (allowed) to use a certain attribute, then that attribute cannot appear in the instance document.

    Then again, defining attributes that are not used is allowed, it is not an error. In some cases this could be reasonable, for example to ease adoption of features planned for the future or to allow importing or including the schema into another schema which would make use of those attributes.

    An attribute within an attributeGroup
    can only occur once within the valid
    xml document. for example:

    <?xml version="1.0"?> <element1
    attrib1="first second third"
    attrib1="first second third"/>

    is not valid because there is a
    duplicate ‘attrib1’, correct?

    Your code example is clear: that is not allowed in XML. As stated in the XML recommendation: “An attribute name MUST NOT appear more than once in the same start-tag or empty-element tag.” Then again, the claim you wrote above your code example is not exactly correct. It is possible that the same attribute can appear multiple times within a valid XML document. It just has to appear on different elements. Duplicating attributes on one element is not allowed. However, you can duplicate elements so that they all have the same attributes.

    Not allowed:

    <element1 attrib1="first second third" attrib1="first second third"/>
    

    Allowed:

    <element1 attrib1="first second third"/>
    <element1 attrib1="first second third"/>
    

    As a corner case, duplicate attribute names applies to expanded names of the attributes.

    <element ns1:attrib="value" ns2:attrib="value"/>
    

    is not allowed, if both prefixes ns1 and ns2 resolve to same namespace URI.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a reasonable size flat file database of text documents mostly saved in

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.