[英]XSD elements in C#
我有一個XSD文件,我需要獲取其中所有元素名稱的列表。
我嘗試了以下方法:
openFileDialog1.ShowDialog();
tbSchema.Text = openFileDialog1.FileName;
cbElement.Items.Clear();
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add("", tbSchema.Text);
schemaSet.Compile();
XmlSchema customerSchema = null;
foreach (XmlSchema schema in schemaSet.Schemas())
{
customerSchema = schema;
}
foreach (XmlSchemaElement element in customerSchema.Elements.Values)
{
cbElement.Items.Add(element.Name);
}
但它仍然不起作用。
您可以嘗試這樣的事情:
XmlDocument doc = new XmlDocument();
doc.Load("D:\\schema.xsd"); // Load the document from the root of an ASP.Net website
XmlElement schemaElement = doc.DocumentElement; // The root element of the schema document is the <schema> element
string elementName = schemaElement.LocalName; // This will print "schema"
foreach (XmlNode ele in schemaElement.ChildNodes)
{
if (ele.LocalName == "element")
{
.....
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.