all groups > dotnet xml > august 2004 >
You're in the

dotnet xml

group:

root from Schema


Re: root from Schema Zafar Abbas [MSFT]
8/30/2004 1:09:05 PM
dotnet xml:
All the top level elements are potential roots for an intance document. You
can get all top level elements of a XSD Schema from the Elements property of
the XmlSchema object. For example, for the following schema:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="a"
xmlns="a" elementFormDefault="qualified">
<xsd:element name="top1" type="xsd:string"/>
<xsd:element name="top2" type="xsd:string"/>
<xsd:complexType name="documentType">
<xsd:sequence>
<xsd:element name="local1" type="xsd:string"/>
<xsd:element name="local2" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

The following code prints out all qualified names of the top level elements:

XmlSchema schema = XmlSchema.Read(new XmlTextReader("test.xsd"), null);

schema.Compile(null);

foreach (XmlSchemaElement e in schema.Elements.Values)

{

Console.WriteLine(e.QualifiedName);

}




[quoted text, click to view]

root from Schema Petr Votoèek
8/30/2004 3:15:34 PM
Hi all, does anybody know how to get all possible roots form XML Schema? I
think all elements without parents are possible roots. Is it true??

Thanks, Petr.


AddThis Social Bookmark Button