Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
hello, i've wasted a whole day for this, can't find the solution.

i have the following main schema:
XML
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">  
  <xs:element name="Users">
    <xs:complexType>     
      <xs:attribute name="FirstName" type="xs:string" use="optional" />
      <xs:anyAttribute namespace="http://www.w3.org/2001/AppLog"/>
    </xs:complexType>
  </xs:element>
</xs:schema>


i want to use the "anyAttribute" to get an attribute from a specific schema, so i declared this secondary schema:

XML
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://www.w3.org/2001/AppLog">
  <xs:attribute name="SystemUsers" type="xs:string" default="abc"/>
</xs:schema>


then, i tried to validate the schema against this xml:
HTML
<br />
<Users UserPreferencesSafe=""abcd"" SystemUsers=""abc""/><br />


i do it with adding the 2 schemas to the schema set (XMLSchemaSet.Add),
then i use the XMLDocument.Validate with this schema set.

i get:
The validation raised a error:The 'SystemUsers' attribute is not allowed.

by the way, if i use anyAttribute namespace="##any", and add the 2 schemas it works. but i need to be specific.

what am i missing?
thanks.
Posted

1 solution

It looks like you misuse complexType: you cannot specify content of complex type without intermediate XSD node describing the type of complex type content, such as sequence, like in this example:

XML
<xs:element name="ExistingRecord">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="ExistingFieldElement" type="xs:string" />
        </xs:sequence>
        <xs:anyAttribute />
    </xs:complexType>
</xs:element>


This example is extracted from http://msdn.microsoft.com/en-us/library/aa562055.aspx[^].

I'm not sure if this is the only problem, but this is the first one which caught my eye.

—SA
 
Share this answer
 
Comments
arielbeck 1-Feb-12 6:22am    
but i dont need an extra element, only an attribute...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900