Académique Documents
Professionnel Documents
Culture Documents
home help
articles
quick answers
discussions
features
community
Search for articles, questions, tips
Next
Article Browse Code Stats Revisions Alternatives Comments & Discussions (13)
About Article
Pull metadata from a schema or generate XML mappers Type Licence Article CPOL 13 Oct 2008 24,786 749 24 times
Introduction
This article shows how to use a Schema Object Model(SOM) navigator as an arbitrary schema. This is useful when you have a schema and want to generate your own mapping or want to build a custom XML generator or XSD based code generator.
Top News
Microsoft took a big risk with Windows 8 and it's starting to backfire
Get the Insider News free each morning.
Related Videos
www.codeproject.com/Articles/30109/Parsing-XSD-Schema-with-SOM
1/4
10/26/13
V a l i d a t i o n E v e n t H a n d l e r ( V a l i d a t i o n C a l l b a c k O n e ) ; / /T h eC o m p i l em e t h o dw i l lt h r o we r r o r s / /e n c o u n t e r e do nc o m p i l i n gt h es c h e m a x s e t . C o m p i l e ( ) ; } r e t u r ns c h e m a ;
Related Articles
An XML Schema Definition (XSD) Editor Parsing and Interpreting XSD Using LINQ WSDL and Schema Parser Parsing XML using a C++ wrapper for SAX2 XSD Tutorial - Part 2 of 5 Conventions & Recommendations
Collapse | Copy Code
p r i v a t es t a t i cv o i dV a l i d a t i o n C a l l b a c k O n e ( o b j e c ts e n d e r ,V a l i d a t i o n E v e n t A r g sa r g s ) { C o n s o l e . W r i t e L i n e ( " E x c e p t i o nS e v e r i t y :"+a r g s . S e v e r i t y ) ; C o n s o l e . W r i t e L i n e ( a r g s . M e s s a g e ) ; }
p r i v a t es t a t i cv o i dT r a v e r s e S O M ( s t r i n gx s f F i l e n a m e ) { X m l S c h e m ac u s t S c h e m a=R e a d A n d C o m p i l e S c h e m a ( x s f F i l e n a m e ) ; f o r e a c h( X m l S c h e m a E l e m e n te l e mi n { } } P r o c e s s E l e m e n t ( e l e m ) ; c u s t S c h e m a . E l e m e n t s . V a l u e s )
XML Schema Reader Writer Plugin for VS 2005/2008 Resources Files (.resx vs .resources) Chapter Excerpt - LINQ Quickly XML for Beginners LINQ to XSD Generate Sample XML from XSD Extract an XML Schema from a .NET 2.0 ConfigurationSection subclass for Configuration Validation & Intellisense in Visual Studio An XSD to .NET language code class generator that adds real punch to Microsoft's XSD Tool UDDI Explorer: Tool for searching web services How to Troubleshoot Schemas in BizTalk Server 2006 Validating SOAP Message against WSDL A cool utility to convert XML schemas to classes Generating Word Reports / Documents No-namespace/Chameleon Include Support for .NET 1.1 ExpandingTable with DesignTime support
Only an element can contain attributes... so it's handled in a little special way:
Collapse | Copy Code
Process the C h o i c e& S e q u e n c e elements generically (this handles the type casting required):
Collapse | Copy Code
p r i v a t es t a t i cv o i dP r o c e s s I t e m C o l l e c t i o n ( X m l S c h e m a O b j e c t C o l l e c t i o no b j s ) { f o r e a c h( X m l S c h e m a O b j e c to b ji no b j s ) P r o c e s s S c h e m a O b j e c t ( o b j ) ; } p r i v a t es t a t i cv o i dP r o c e s s S c h e m a O b j e c t ( X m l S c h e m a O b j e c to b j ) { i f( o b ji sX m l S c h e m a E l e m e n t ) P r o c e s s E l e m e n t ( o b ja sX m l S c h e m a E l e m e n t ) ; i f( o b ji sX m l S c h e m a C h o i c e ) P r o c e s s C h o i c e ( o b ja sX m l S c h e m a C h o i c e ) ; i f( o b ji sX m l S c h e m a S e q u e n c e ) P r o c e s s S e q u e n c e ( o b ja sX m l S c h e m a S e q u e n c e ) ; }
www.codeproject.com/Articles/30109/Parsing-XSD-Schema-with-SOM
2/4
10/26/13
Points of Interest
There's a lot of type checking and casting. That's inherent in the data model used in the SOM. It's not a strongly typed data structure. So you have to check, cast, then use. It would be an interesting exercise to generate a strongly typed XSD model, but I'll leave that for another article.
History
2008-10-10: Article created
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
CodingBruce
Engineer Big Company United States My professional career began as a developer fixing bugs on Microsoft Word97 and I've been fixing bad habits ever since. Now I do R&D work writing v1 line of business applications mostly in C#/.Net. I've been an avid pilot/instructor for 13+ years, I've built two airplanes and mostly fly gliders now for fun. I commute in an all-electric 1986 BMW 325 conversion. I'd like to get back to my academic roots of programming 3D analysis applications to organize complex systems. Article Top
www.codeproject.com/Articles/30109/Parsing-XSD-Schema-with-SOM
3/4
10/26/13
Search this forum Profile popups Spacing Relaxed Noise Very High Layout Normal Per page 10
Go
LinqToXsd Update Thanks a lot! parsing XSD schema Re: parsing XSD schema Linq2Xsd makes this silly The lights go on... How to extract Description that is within annotation tag?Please help! [modified] Re: How to extract Description that is within annotation tag?Please help! [modified] [modified] Problem with nested <xs:group> Schema w/LinqToXsd
Last Visit: 31-Dec-99 18:00 General News Last Update: 26-Oct-13 1:55 Suggestion Question
6-May-12 2:31 18-Mar-12 12:50 22-Nov-11 11:06 23-Nov-11 1:23 23-Sep-11 13:38 6-Jun-11 21:09 18-May-11 10:58
RayD
23-Sep-11 13:25
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
Permalink | Advertise | Privacy | Mobile Web03 | 2.7.1310025.1 | Last Updated 13 Oct 2008 Layout: fixed | fluid Article Copyright 2008 by CodingBruce Everything else Copyright CodeProject, 1999-2013 Terms of Use
www.codeproject.com/Articles/30109/Parsing-XSD-Schema-with-SOM
4/4