2010-10-19 43 views
1

我已經加載到一個XML模式下面的模式:在C#中的XmlSchema發現的schemaLocation

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

我想以檢索字符串 「_1.xsd」

我要如何的XmlSchema API達到的schemaLocation值? 將schemaSet工作更好?

感謝

回答

1

我終於用這個:

schema.Includes[0] as XmlSchemaImport; 
var wsdlId = schemaImport.SchemaLocation; 
0
using System.Xml.Schema; 
using System.IO; 
using System.Reflection; 

這應該工作,可能會引發一些錯誤,因爲我沒有在一個IDE編譯它作爲即時通訊不是在開發機器大氣壓。

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