473,654 Members | 3,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading and Iterating through an XSD Schema?

I have been looking around for a sample on how to read an XSD schema and iterate
through the elements to display them.

I am working in VB.Net and I have looked at all of the docs on msdn and can find
plenty of samples on how to read it in and then write it write back out...with
no manipulation or analysis before writing. I load the XMLSchema object but
can't get into the right collection of objects to get back any valid items.

I was just tyring to do a load a schema that is not terrible complex and list
the names of each of the Elements in a textbox control on a form...I will go for
attributes for each element after that.

Anyone have an article that I can read...any simple samples.

Thanks in advance,

Cy Huckaba
Austin, TX
Nov 11 '05 #1
3 22434
Hi Austin,

From XMLSchema object's property, we can only get the inforamtion about
namespace and SourceUri. However, XSD file is also a text file in XML
format. I think you can read it as a common XML file with XMLTextReader and
list all elements nodes in the textbox.

Luke

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/se...s/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026."

Nov 11 '05 #2
You have full access to what's called the SOM (Schema Object Model). That
includes knowing if an element is a simple or complex type, its particles
(i.e. child elements), etc.
The Items/Elements/Attributes will only give you those items that are
defined globally, NOT those that are local elements, which is quite common
and, IMO, a better design practice if the elements/types are not going to be
reused anywhere else.
The easiest way is to get first the top-level elements through the .Elements
property. Here's how to iterate:

foreach (DictionaryEntr y entry in schema.Elements )
{
if (entry.Value is XmlSchemaElemen t)
{
//We have an element
}
}

Next, you can query its type (to see if they have a complexType definition)
and keep going to list the children. This is done as follows (requires a
recursive function to be effective, actually, but you get the idea):

XmlSchemaElemen t rootelement = (XmlSchemaEleme nt) entry.Value;
if (rootelement.Sc hemaType is XmlSchemaComple xType)
{
XmlSchemaComple xType roottype =
(XmlSchemaCompl exType)rootelem ent.SchemaType;

// Check for a sequence child element (particle content model). May be a
choice too, for example.
if (roottype.Parti cle is XmlSchemaSequen ce)
{
XmlSchemaSequen ce rootseq = (XmlSchemaSeque nce) roottype.Partic le;
foreach (Dictionary innerentry in rootseq.Items)
{
if (entry.Value is XmlSchemaElemen t)
{
//Recurse forever ;)
}
}
}
}

--
.../dcazz
Daniel Cazzulino
DEVerest - Lagash
Tel +54 (0) 11 4247 7396
www.deverest.com.ar
www.lagash.com
dotnetopensrc.s ourceforge.net

Coauthor of:
Beginning C# Web Applications with Visual Studio .NET
Beginning Web Programming using VB.NET and Visual Studio .NET
Professional ASP.NET Server Controls: Building Custom Controls with C#
ASP.NET Components Toolkit

"He who is good for making excuses, is seldom good for anything else."

"Cy Huckaba" <ru******@t-3.com> wrote in message
news:e0******** ******@tk2msftn gp13.phx.gbl...
OK, at least I'm not going crazy.

If I put an xpath navigator on it Can I cast the nodes I want into XMLSchema Elements so I can have access to datatypes, etc?

I'll give it a shot...thanks for the reply.

Cy

"MSFT" <lu******@onlin e.microsoft.com > wrote in message
news:cE******** ******@cpmsftng xa06.phx.gbl...
Hi Austin,

From XMLSchema object's property, we can only get the inforamtion about
namespace and SourceUri. However, XSD file is also a text file in XML
format. I think you can read it as a common XML file with XMLTextReader and list all elements nodes in the textbox.

Luke

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/se...s/ms03-026.asp and/or to visit Windows Update at http://windowsupdate.microsoft.com to install the patch. Running the SCAN program from the Windows Update site will help to insure you are current with all security patches, not just MS03-026."


Nov 11 '05 #3
Yes, you can do this. You also can consider SOM as Daniel suggested. (Thank
for Daniel's suggestion)

Luke

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #4

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

Similar topics

0
1417
by: Dave Mc | last post by:
First off I apologize for the length of this post. Given the following for XML <?xml version="1.0" encoding="Windows-1252"?> <Product Name="Product1" xmlns:d2p1="InspectionFile"> <InspectionSite Name="Site1"> <Fiducial> <Name>Loc1Fid1</Name> <ModelFileName>Loc1Fid1Model.mim</ModelFileName> <FidSearchRegion>
3
1332
by: ceplma | last post by:
Hi, I love Kate XML plugin <http://kate.kde.org/> which understands XML document structure by reading output of dtdparse. However, DTDs seem to be kind of dying out (slowly, but sure) and everybody turns to schema. Would it be possible to create a variant of dtdparse, which would produce the same output (i.e., it would be useful with Kate, dtdformat, etc.) but based on reading Schema, not DTD? Or is it the most stupid idea under the...
0
1453
by: chris.millar | last post by:
I am using the ReadXMLSchema method of system.data.dataset to read a schema into a dataset. I have an XML file that I build up and wish to do a .Update against a database. The dataset doesn't have a schema and takes the following form: xml: <?xml version="1.0" encoding="utf-8"?> <DataSetEntities xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:guids="urn:schemas-microsoft-com:guids" xmlns="C:/DACXML/EntityAttribute.xsd">
1
4377
by: Michael Palmer | last post by:
I'm reading xml from SQL Server 2K with VB.net using an XSD schema file and SQLXML 3.0. I have the below code working fine, but I'd like to change the code from reading the schema file from a directory to reading the schema as an embedded resource. Here's my current code, what would I need to change?? Dim strm As Stream Dim strmReader As StreamReader Dim cmd As New SqlXmlCommand("MyConnectionString") Dim xmlDoc As New XmlDocument
3
1282
by: Paul Bromley | last post by:
I have an application that needs to utilise an XML file produced by an external application. However I am having problems getting this into a Dataset using dsOrganisation.ReadXml("c:\testmodify.xml"). I am getting an error that states:- The same table (Address) cannot be the child table in tow nested relations. Address seems to be an element in a number of the tables conatined in the xml file. What can I do? I have no control over the...
0
1694
by: c.w.browne | last post by:
Hi, Ive had a bit of a look around for other people with this problem and cant find anything that solves it in my case, so I'm afraid im going to have to bother you all with a post of my own. Essentially, I am trying to read in an xml schema and then an xml document into a dataset using ReadXmlSchema and then ReadXml. When i do this, i end up with a table in the dataset (which i assume is created when i read the schema), but no rows...
3
1551
by: jhowey | last post by:
Hi, I would like my default ValidationType to be Auto. Now let's say I have both a DTD and an XSD file for this XML file being validated. While it's ValidationType.Auto, it will validate the DTD, but will not even attempt to read/validate the namespace or even check if schema file exists. I suppose it's a resolver problem; anyone have any insight on how I can
25
5843
by: 7stud | last post by:
I can't break out of the for loop in this example: ------ import sys lst = for line in sys.stdin: lst.append(line) break
6
22517
by: =?Utf-8?B?UmljaA==?= | last post by:
'--this code works but only reads text into one column when contains multiple cols Dim ds1x As New DataSet Dim ConStr As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dir1A\;Extended Properties=""Text;HDR=No;FMT=Delimited\""" Dim conn1x As New OleDb.OleDbConnection(ConStr) Dim dax1 As New OleDbDataAdapter("Select * from testabc1x.txt", conn1x)
0
8372
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8285
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8814
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8706
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.