Gady
Gady

Reputation: 1514

finding schemaLocation in c# XmlSchema

i have the following schema loaded into an xmlSchema :

...
<xs:import schemaLocation="\_1.xsd" namespace="http://tempuri.org/" />
...

i want to retrive the string "_1.xsd"

how do i reach the schemaLocation value from XmlSchema API ? will schemaSet work better ?

Thanks

Upvotes: 2

Views: 1161

Answers (2)

Gady
Gady

Reputation: 1514

i finally used this :

schema.Includes[0] as XmlSchemaImport;
var wsdlId = schemaImport.SchemaLocation;

Upvotes: 2

Stephen
Stephen

Reputation: 3084

using System.Xml.Schema;
using System.IO;
using System.Reflection;

This should work, might throw some errors, as I didnt compile it in an IDE as im not on a Dev machine atm.

string xsd = "example.xsd";

FileStream fs;
XmlSchema schema;

fs = new FileStream(xsd, FileMode.Open);
schema = XmlSchema.Read(fs, new ValidationEventHandler(ShowCompileError));

foreach (XmlSchemaObject externalSchema in schema.Includes)
{
    string schemaLoc = (XmlSchemaExternal)externalSchema.SchemaLocation.ToString();
}

Upvotes: 0

Related Questions