Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / April 2006

Tip: Looking for answers? Try searching our database.

traversing a schemaset to arbitrary depth

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dave.dolan - 25 Apr 2006 15:07 GMT
The example on MSDN for traversal of a schemaset is great if all you have are
top level elements, but I have complex schemas with several levels of complex
items.  I seem to be only able to access the top level elements... what  am I
missing?  I'm trying to use the XML schema to represent the structure of xml
documents that are substituting for domain objects so I can avoid
serialization (and access virtual 'property' values with Xpath - again
without serialization and/or reflection)  I need to use schemas here because
my web service clients still need to be able to generate the concrete domain
objects, but my service is agnostic of specific types.

Depth anyone?
dave.dolan - 26 Apr 2006 15:23 GMT
I was able to dig up some sample code, but it didn't compile

void Start()
        {
         XmlSchemaComplexType complexType;
         foreach (XmlSchemaType type in xs.SchemaTypes.Values)
         {
          complexType = type as XmlSchemaComplexType;
          if (complexType != null)
           TraverseParticle(complexType.ContentTypeParticle);
         }

         foreach (XmlSchemaElement el in xs.Elements.Values)
          TraverseParticle(el);
       }

       void TraverseParticle(complexType.ContentTypeParticle)  // <-- This
line is the offender
       {
         if (particle is XmlSchemaElement)
         {
          XmlSchemaElement elem = particle as XmlSchemaElement;

          if (elem.RefName.IsEmpty)
          {
           XmlSchemaType type = (XmlSchemaType)elem.ElementSchemaType;
           XmlSchemaComplexType complexType = type as XmlSchemaComplexType;
           if (complexType != null && complexType.Name == null)
            TraverseParticle(complexType.ContentTypeParticle);
          }
         }
         else if (particle is XmlSchemaGroupBase)
         { //xs:all, xs:choice, xs:sequence
              XmlSchemaGroupBase baseParticle = particle as
XmlSchemaGroupBase;
                 foreach (XmlSchemaParticle subParticle in
baseParticle.Items)
                   TraverseParticle(subParticle);
             }
       }

so I actually found a way to fix it up, changing the line in question to
"void TraverseParticle(XmlSchemaParticle particle)"

That code actually does what I need here.  I have added a delagate to be
called at every 'visit' in my code so I can 'do something' while I"m
traversing it at each node.  So, I think the problem with the example code
was a simple copy-paste error.  I know someone will run into this later at
some point so I figured I'd post it.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.