473,386 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Load an XSD and expand include and import elements

How do I read in an XSD file that includes and imports lots of other XSD
files, so that I can enumerate all the elements/attributes defined by the XSD.
Aug 19 '08 #1
5 9164
tony lock wrote:
How do I read in an XSD file that includes and imports lots of other XSD
files, so that I can enumerate all the elements/attributes defined by the XSD.
Load the schema into an XmlSchemaSet:
http://msdn.microsoft.com/en-us/libr...maset.add.aspx
then use the properties/methods of the XmlSchemaSet to access the
elements/attributes/types defined.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 19 '08 #2
XmlSchemaSet can do this (see below); note that the set.XmlResolver needs to
be able to locate the related schemas, which is easiest if you start with
something like an XmlReader that knows where the file came from [in
contrast, say, to a MemoryStream] - but if you need to you can write your
own XmlResolver (I've written resolvers from resource files, databases,
etc).

XmlSchemaSet set = new XmlSchemaSet();
set.Add(XmlSchema.Read(XmlReader.Create("XMLSchema 1.xsd"), null));
set.Compile();
foreach (XmlSchemaType obj in set.GlobalTypes.Values)
{
Console.WriteLine("{0}: {1}", obj.Name, obj.SourceUri);
}

Marc
Aug 19 '08 #3
Thanks for that unfortunately when I do the compile I get an exception

The global attribute 'http://www.w3.org/XML/1998/namespace:lang' has already
been declared.

It appears all the xsd's which are being imported include imports of the
basic declarations. Is there any way to tell the XmlSchemaSet to ignore all
but the first definition of any element/attribute

"Marc Gravell" wrote:
XmlSchemaSet can do this (see below); note that the set.XmlResolver needs to
be able to locate the related schemas, which is easiest if you start with
something like an XmlReader that knows where the file came from [in
contrast, say, to a MemoryStream] - but if you need to you can write your
own XmlResolver (I've written resolvers from resource files, databases,
etc).

XmlSchemaSet set = new XmlSchemaSet();
set.Add(XmlSchema.Read(XmlReader.Create("XMLSchema 1.xsd"), null));
set.Compile();
foreach (XmlSchemaType obj in set.GlobalTypes.Values)
{
Console.WriteLine("{0}: {1}", obj.Name, obj.SourceUri);
}

Marc
Aug 19 '08 #4
On Aug 19, 6:57*pm, tony lock <tonyl...@discussions.microsoft.com>
wrote:
Thanks for that unfortunately when I do the compile I get an exception

The global attribute 'http://www.w3.org/XML/1998/namespace:lang'has already
been declared.

It appears all the xsd's which are being imported include imports of the
basic declarations. Is there any way to tell the XmlSchemaSet to ignore all
but the first definition of any element/attribute
No. XmlSchemaSet only reads well-formed and valid XML Schema
declarations. If an .xsd file, after include expansion, ends up
defining several things twice, it's just not valid. If the schemas are
your own, you should consider fixing them.
Aug 19 '08 #5
Unfortunately they are not.

"Pavel Minaev" wrote:
On Aug 19, 6:57 pm, tony lock <tonyl...@discussions.microsoft.com>
wrote:
Thanks for that unfortunately when I do the compile I get an exception

The global attribute 'http://www.w3.org/XML/1998/namespace:lang'has already
been declared.

It appears all the xsd's which are being imported include imports of the
basic declarations. Is there any way to tell the XmlSchemaSet to ignore all
but the first definition of any element/attribute

No. XmlSchemaSet only reads well-formed and valid XML Schema
declarations. If an .xsd file, after include expansion, ends up
defining several things twice, it's just not valid. If the schemas are
your own, you should consider fixing them.
Aug 19 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Weston C | last post by:
I know of course that you can use <script src=""></script> in an HTML document to include javascript code you don't want to spill all over the page. I'm wondering if there's a way to include...
7
by: peter | last post by:
I use the click-to-expand menu at http://javascript.internet.com/navigation/click-to-expand-menu.html This works fine, but is there a way to expand or collapse all the menus? An example of how...
1
by: WStoreyII | last post by:
what exactly is the difference between import and include? For Example if i had a schema called common, that had some common elements that i use such as address, phone ect. And then i created a...
3
by: James J. Besemer | last post by:
I would like to champion a proposed enhancement to Python. I describe the basic idea below, in order to gage community interest. Right now, it's only an idea, and I'm sure there's room for...
5
by: Konstantin Andreev | last post by:
Recently I became interested, - Are the data, bulk loaded in the table with LOAD utility, consume the same disk space as loaded with IMPORT utility? The answer turned out to be NOT ! Here is a...
1
by: jrs362 | last post by:
One more problem... I need to write a method(Which i'm calling "expand") that takes an int array as one of its parameters and returns a new int array that is 5 elements longer. The contents of the...
11
by: Nospam | last post by:
I don't know what it is I am doing wrong, I am trying to get the menus to either expand or contract based on their previous states, i.e if already expanded if clicked again contract, and if...
4
hemantbasva
by: hemantbasva | last post by:
We have designed an aspx page having five ajax tab in it. the data of first four are designed on page whereas for the fifth tab it renders a user control named MYDOMAIN. in the tab container's even...
0
by: liz0001 | last post by:
I have seen many examples on how to use the .load() function to load in static elements, but I am trying to load a dynamic element, specifically a scrollable. I have gotten it to the point where:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.