Monday, March 12, 2012

Reference to an undefined name !

Hello all,
I am trying to add a XML schema but I get this error for the following XSD.
Msg 2307, Level 16, State 1, Line 1
Reference to an undefined name 'fullpersoninfo'
What am I doing wrong?. Please help!
******************
create XML schema collection test_schema_coll
as
N'<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="http://MyXMLDocSchema">
<xs:element name="employee" type="fullpersoninfo">
<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="fullpersoninfo">
<xs:complexContent>
<xs:extension base="personinfo">
<xs:sequence>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>'
******************
Thanks,
Ganesh
Hi Ganesh,
Couple of things:
1. You need to define a namespace prefix for the items in your new schema in
order to refer to them. Else, you're referring to a type in no namespace.
2. Your global element declaration is surrounding the definition of your
complexTypes.
Hope this helps
Bob Beauchemin
http://www.SQLskills.com/blogs/bobb
Here's one that works:
create XML schema collection test_schema_coll
as
N'<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://MyXMLDocSchema"
elementFormDefault="qualified" targetNamespace="http://MyXMLDocSchema">
<!-- personinfo in the target namspace -->
<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<!-- fullpersoninfo in the target namspace -->
<!-- extention of tns:personinfo, not personinfo in no namespace -->
<xs:complexType name="fullpersoninfo">
<xs:complexContent>
<xs:extension base="tns:personinfo">
<xs:sequence>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- global element declaration using tns:fullpersoninfo -->
<!-- moved to bottom -->
<!-- not fullpersoninfo in no namespace -->
<xs:element name="employee" type="tns:fullpersoninfo">
</xs:element>
</xs:schema>'
"Ganesh Muthuvelu" <GaneshMuthuvelu@.discussions.microsoft.com> wrote in
message news:BBB836E3-1EEE-4333-A884-360340A52B1A@.microsoft.com...
> Hello all,
> I am trying to add a XML schema but I get this error for the following
> XSD.
> Msg 2307, Level 16, State 1, Line 1
> Reference to an undefined name 'fullpersoninfo'
> What am I doing wrong?. Please help!
> ******************
> create XML schema collection test_schema_coll
> as
> N'<?xml version="1.0"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" targetNamespace="http://MyXMLDocSchema">
> <xs:element name="employee" type="fullpersoninfo">
> <xs:complexType name="personinfo">
> <xs:sequence>
> <xs:element name="firstname" type="xs:string"/>
> <xs:element name="lastname" type="xs:string"/>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="fullpersoninfo">
> <xs:complexContent>
> <xs:extension base="personinfo">
> <xs:sequence>
> <xs:element name="address" type="xs:string"/>
> <xs:element name="city" type="xs:string"/>
> <xs:element name="country" type="xs:string"/>
> </xs:sequence>
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
> </xs:element>
> </xs:schema>'
> ******************
> Thanks,
> Ganesh

No comments:

Post a Comment