468,510 Members | 1,745 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,510 developers. It's quick & easy.

Parsing XML Schema, How To, please

Hi! I have an Excel 2003 Schema I need to parse to extract elements names.
I am puzzled which System.Xml object can help me. Here's the example of my
schema:

I need to get a collection of element names(TemplateB62,TemplateC62 ......)

<?xml version='1.0' encoding='UTF-8'?>
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://tempuri.org/XMLSchema.xsd">
<xsd:annotation>XSD Schema generated with Excel XML Toolbox</xsd:annotation>
<xsd:element name="Root" type="RootType"/>
<xsd:complexType name="RootType">
<xsd:all>
<xsd:element name="TemplateB62" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>
<xsd:element name="TemplateC62" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>
<xsd:element name="TemplateD62" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>
<xsd:element name="TemplateE62" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>

<xsd:element name="TemplateK86_1" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
Thank you in advance,

--Michael
Nov 12 '05 #1
2 1538
Load the XSD in a XmlSchema object and call Compile(), you can then access
all global elements via the
Elements collection.[1]

Given an XSD file called schema.xsd the code looks like:
Code:
XmlSchema schema = XmlSchema.Read(new XmlTextReader("schema.xsd"),null);
schema.Compile();
foreach (XmlSchemaElement elemenet in schema.Elements.Values)
{
// Access the Element properties here , like QualifiedName etc.
}
[1]
http://msdn.microsoft.com/library/de...mentstopic.asp
Thanks.
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
Hi! I have an Excel 2003 Schema I need to parse to extract elements names.
I am puzzled which System.Xml object can help me. Here's the example of my schema:

I need to get a collection of element names(TemplateB62,TemplateC62 .......)
<?xml version='1.0' encoding='UTF-8'?>
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/XMLSchema.xsd">
<xsd:annotation>XSD Schema generated with Excel XML Toolbox</xsd:annotation> <xsd:element name="Root" type="RootType"/>
<xsd:complexType name="RootType">
<xsd:all>
<xsd:element name="TemplateB62" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>
<xsd:element name="TemplateC62" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>
<xsd:element name="TemplateD62" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>
<xsd:element name="TemplateE62" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>

<xsd:element name="TemplateK86_1" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
Thank you in advance,

--Michael

Nov 12 '05 #2
Thank you very much for taking a look. Your answer brought me closer to the
solution. I tried your approach and only get the Root of the schema file.
I can not seem to be able to reach the elements.

Please let me know if you know what I do wrong.

Numerous thanks in advance,

--Michael
"Zafar Abbas" wrote:
Load the XSD in a XmlSchema object and call Compile(), you can then access
all global elements via the
Elements collection.[1]

Given an XSD file called schema.xsd the code looks like:
Code:
XmlSchema schema = XmlSchema.Read(new XmlTextReader("schema.xsd"),null);
schema.Compile();
foreach (XmlSchemaElement elemenet in schema.Elements.Values)
{
// Access the Element properties here , like QualifiedName etc.
}
[1]
http://msdn.microsoft.com/library/de...mentstopic.asp
Thanks.
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
Hi! I have an Excel 2003 Schema I need to parse to extract elements names.
I am puzzled which System.Xml object can help me. Here's the example of

my
schema:

I need to get a collection of element names(TemplateB62,TemplateC62

.......)

<?xml version='1.0' encoding='UTF-8'?>
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://tempuri.org/XMLSchema.xsd">
<xsd:annotation>XSD Schema generated with Excel XML

Toolbox</xsd:annotation>
<xsd:element name="Root" type="RootType"/>
<xsd:complexType name="RootType">
<xsd:all>
<xsd:element name="TemplateB62" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>
<xsd:element name="TemplateC62" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>
<xsd:element name="TemplateD62" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>
<xsd:element name="TemplateE62" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>

<xsd:element name="TemplateK86_1" type="xsd:string" minOccurs="0"
nillable="true" form="qualified"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
Thank you in advance,

--Michael


Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by my_questions | last post: by
4 posts views Thread by Pushya | last post: by
8 posts views Thread by pradeepsarathy | last post: by
1 post views Thread by padmagvs | last post: by
1 post views Thread by JJadhav | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.