I have the following xsd files:
SchemaA
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://schemaA"
elementFormDefault="qualified"
xmlns="http://schemaA"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Configuration">
<xs:complexType>
<xs:all>
<xs:element name="StationNumber" type="xs:int">
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
SchemaB
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://schemaB"
elementFormDefault="qualified"
xmlns="http://schemaB"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attribute name="Name" type="xs:string" />
</xs:schema>
I’m trying to reference them and use them from the following XML:
<?xml version="1.0"?>
<Configuration xmlns="http://schemaA"
xmlns:ba="http://schemaB">
<StationNumber ba:Name="aaa">1</StationNumber>
</Configuration>
Visual Studio 2008 underlines ba:Name as error with the description: The ‘http://schemaB:Name‘ attribute is not declared.
Any ideas?
This is not a two schema problem, your schemas do not match your document content. The attribute Name is not listed as one of the possible attributes on Configuration.
Just because you declare a global attribute, it does not mean you can use it wherever you want. You will either have to import one schema into the other, and specify that the attribute can occur in Configuration, as in the first answer given by ewernli above.
Or you permit any attribute from the second namespace to occur in the first schema, e.g.:
CHANGED: following the comment from ewernli below, which correctly points out that this has the additional problem that StationNumber is of a simple type. If you want to prepare the type to take attributes, you need to force it to complex:
Now you can attach the attribute as described above.