Solved

XSD: Attribute is not declared

Posted on 2006-06-09
2
4,026 Views
Last Modified: 2013-11-19
Hello,

I'm having a problem with some XML not being validated accordingly against my schema.  I know that the XML is correct.  However, I cannot seem to generate the appropriate XSD to validate the XML.

My XML is formated as follows:
<?xml version="1.0"?>

<entries xmlns="http://tempuri.org/Test.xsd">
      <entry>
            <person ssn="123-45-6789">firstName lastName</person>
                </entry>
</entries>

The Test.xsd file is formatted as follows:
<?xml version="1.0"?>
<xs:schema id="Test" targetNamespace="http://tempuri.org/Test.xsd" xmlns:mstns="http://tempuri.org/Test.xsd" xmlns="http://tempuri.org/Test.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">

                <xs:element name="entries" msdata:IsDataSet="false" msdata:EnforceConstraints="false">
                                <xs:complexType>
            <xs:choice maxOccurs="unbounded">
            <xs:element name="entry">
            <xs:complexType>
            <xs:sequence>
                                     <xs:element name="person" type="Person" />
                                     <xs:element name="occupation" type="xs:stirng" />
                                </xs:sequence>
                                </xs:element>
                                </xs:choice>
            </xs:complexType>
      </xs:element>

      <xs:complexType name="Person">
            <xs:simpleContent>
                  <xs:extension base="xs:string">
                        <xs:attribute name="ssn" type="xs:string" use="required"/>
                  </xs:extension>
            </xs:simpleContent>
      </xs:complexType>
</xs:schema>
      
I am using the .NET Framework.  When I attempt to validate this XML file using the Test.xsd file, I receive two messages for each <person> I have in my XML file.  The messages are:

"The 'ssn' attribute is not declared." and
"The required attribute 'http://tempuri.org/Test.xsd:ssn' is missing"

It's almost like my xml file is not accessing the correct xsl file.  However, if I remove an <occupation> element from the xml file, it throws an error stating that it's expecting the <occupation> so I know that is accessing the correct XSD file.  I'm really confused.  Thank you so much for your help
0
Comment
Question by:campbel8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
jkmyoung earned 250 total points
ID: 16870988
attributeFormDefault="qualified"
Change to
attributeFormDefault="unqualified"
Otherwise the attribute is expected to be in the namespace http://tempuri.org/Test.xsd"
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16871012
Hi campbel8,
> attributeFormDefault="qualified"

makes the parser expect a qualification for your attribute

This would be valid according your schema
(attributes require a hard prefix, they don't accept the default)

<entries xmlns="http://tempuri.org/Test.xsd" xmlns:tmp="http://tempuri.org/Test.xsd">
     <entry>
          <person tmp:ssn="123-45-6789">firstName lastName</person>
                </entry>
</entries>

this is a bit unworkable
set the value to unqualified and your XML will be valid as well


Cheers!
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question