While a single document can contain only one root element, since the XSD can actually define several valid root elements .
If you really want one type to be valid as the root element, it should be the only type referenced by <element> .
In the above diagram, for example, DocumentInfo and Prerequisite nodes are also valid root elements. To limit your schema to only one valid root node, replace the DocumentInfo and Prerequisite elements with simple complexType definitions:
<xsd:complexType name="DocumentInfoType"> ... </xsd:complexType> <xsd:complexType name="Prerequisite"> .... </xsd:complexType>
UPDATE: to access the element name you just need to look at the Name property in XmlElement:
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") { // This is a valid root node // Note that there will be *more than one* of these if you have multiple elements declare at the base level } }
source share