XSD: Attribute is not declared


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">
            <person ssn="123-45-6789">firstName lastName</person>

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:choice maxOccurs="unbounded">
            <xs:element name="entry">
                                     <xs:element name="person" type="Person" />
                                     <xs:element name="occupation" type="xs:stirng" />

      <xs:complexType name="Person">
                  <xs:extension base="xs:string">
                        <xs:attribute name="ssn" type="xs:string" use="required"/>
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
Who is Participating?
jkmyoungConnect With a Mentor Commented:
Change to
Otherwise the attribute is expected to be in the namespace http://tempuri.org/Test.xsd"
Geert BormansInformation ArchitectCommented:
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">
          <person tmp:ssn="123-45-6789">firstName lastName</person>

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.