简体   繁体   中英

Displaying XML schema elements in treeview in order of appearance in XML

I need to display XSD files in a treeview. I already found one solution for this here ,. but this just displays all the nodes in the file in the order they appear.
What I need is to display them in the order they appear in the XML file, and nested under the elements they will be nested under in the XML file:

<?xml version="1.0" encoding="IBM437"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="cat" type="xs:string"/>
    <xs:element name="dog" type="xs:string"/>

    <xs:element name="pets">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element ref="cat"/>
          <xs:element ref="dog"/>
        </xs:choice>
      </xs:complexType>
    </xs:element>
</xs:schema>

Would be displayed like this:

-Pets
 -Dogs
 -Cats

How do I undentify the root node? I think that once I got that I can recurse into each type in the root elemet to find its name.
I am looking at this XSD specifically .? Should I start from the element called 'Document'. It contains the 2 top level elements in this type of file - 'GrpHdr' and 'OrgnlGrpInfAndSts'.

Is this is a standard way to tackle something like this?

Apparently there isn't since an XSD may contain more then 1 root element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM