简体   繁体   English

按 XML 中出现的顺序在 treeview 中显示 XML 模式元素

[英]Displaying XML schema elements in treeview in order of appearance in XML

I need to display XSD files in a treeview.我需要在 treeview 中显示 XSD 文件。 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 文件中的顺序显示它们,并嵌套在它们将嵌套在 XML 文件中的元素下:

<?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 .?我正在看这个XSD 专门.? Should I start from the element called 'Document'.我应该从名为“文档”的元素开始。 It contains the 2 top level elements in this type of file - 'GrpHdr' and 'OrgnlGrpInfAndSts'.它包含此类文件中的 2 个顶级元素 - 'GrpHdr' 和 '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.显然没有,因为 XSD 可能包含超过 1 个根元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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