开发者

finding schemaLocation in c# XmlSchema

开发者 https://www.devze.com 2023-01-20 08:56 出处:网络
i have the following schema loaded into an xmlSchema : ... <xs:im开发者_如何学Pythonport schemaLocation=\"\\_1.xsd\" namespace=\"http://tempuri.org/\" />

i have the following schema loaded into an xmlSchema :

...
<xs:im开发者_如何学Pythonport 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


i finally used this :

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


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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消