traversing a schemaset to arbitrary depth

Discussion in 'ASP .Net Web Services' started by dave.dolan, Apr 25, 2006.

  1. dave.dolan

    dave.dolan Guest

    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, Apr 25, 2006
    #1
    1. Advertising

  2. dave.dolan

    dave.dolan Guest

    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.
    dave.dolan, Apr 26, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steven
    Replies:
    6
    Views:
    900
    steven
    Aug 27, 2003
  2. Asad

    XML - traversing in VB

    Asad, Apr 16, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    572
    Matt Berther
    Apr 16, 2004
  3. Honestmath
    Replies:
    5
    Views:
    549
    Honestmath
    Dec 13, 2004
  4. Paul McGuire

    defaultdict of arbitrary depth

    Paul McGuire, Aug 17, 2007, in forum: Python
    Replies:
    6
    Views:
    333
    Paddy
    Aug 22, 2007
  5. ëøÏ鹦
    Replies:
    0
    Views:
    88
    ëøÏ鹦
    Oct 30, 2008
Loading...

Share This Page