all groups > dotnet xml > may 2006 >
You're in the

dotnet xml

group:

Cannot resolve the schemaLocation attribute C#


Cannot resolve the schemaLocation attribute C# techie
5/30/2006 3:56:49 AM
dotnet xml:
Hi,
I am using an xml schema (Schema1.xsd) which refers to two other
Schemas as follows.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:plcm-s="http://www.mycompany.com/plcm"
targetNamespace="http://www.mycompany.com/plcm"
elementFormDefault="qualified" attributeFormDefault="unqualified">

<xsd:include schemaLocation="Schema2.xsd"/>
<xsd:include schemaLocation="Schema3.xsd"/>

All three schemas are stored in a Database as strings (SQL Server
2000).
Now I am trying to load the Schema1 from datbase by using the following
code.

public XmlSchema GetSchema()
{
XmlSchema PLCMSchema = null;
String schema1StringFromDatabase=//Get Schema1 from
Database
String schema2StringFromDatabase=//Get Schema2 from
Database
String schema3StringFromDatabase=//Get Schema3 from
Database
try
{
TextReader schemaTextReader = new
StringReader(schema1StringFromDatabase) as TextReader;
XmlTextReader schemaXmlReader = new
XmlTextReader(schemaTextReader);
XmlSchema schemaPLCM = XmlSchema.Read(schemaXmlReader,
new ValidationEventHandler(schemaSet_ValidationEventHandler));

XmlSchemaSet schemaset = new XmlSchemaSet();
schemaset.ValidationEventHandler += new
ValidationEventHandler(schemaSet_ValidationEventHandler);
schemaset.Add(schemaPLCM);
schemaset.Compile();


foreach (XmlSchema schema in schemaset.Schemas())
{
PLCMSchema = schema;
}
}
catch (Exception exception)
{

System.Windows.Forms.MessageBox.Show("Error in
PLCMWorkbenchShared.GetSchema()" + System.Environment.NewLine +
exception.Message);
}
return PLCMSchema;
}

But the SchemaSet_ValidationEventHandler Returns the error "Cannot
resolve the schemaLocation attribute".

Is there any way I can load the Schema1 from Database without errors
(the other two schemas are also in database)?

Any help is greatly appreciated.

Thanks,
Ramesh
Re: Cannot resolve the schemaLocation attribute C# Priya Lakshminarayanan
5/30/2006 10:35:28 AM
Since schema2 and schema3 are resources in the database, the schema set's
default XmlResolver (XmlUrlResolver) will not know how to get them.
You can do one of two things:
1. Set XmlResolver property on XmlSchemaSet to null and add schema1 to set.
Then manually traverse the Includes of schema1 and set schema2 and schema3
objects as includes. Then call compile()
2. You can use a custom resolver that returns back the schema objects from
the database when the schema set requests the schemas for location
schema2.xsd and schema3.xsd

For a sample on how to do option 2, see
http://blogs.msdn.com/mfussell/archive/2004/10/03/237416.aspx

Thanks,
Priya

[quoted text, click to view]

AddThis Social Bookmark Button