0

我正在做一个简单的项目,它从源代码中获取一个 xml 文件(这是应用程序中名为“diagrams”的文件夹)。所以当我启动应用程序时有一个按钮。当您单击按钮时,它将带我进入源“图表”文件夹。在图表文件夹中,有 xml 文件。当我选择其中任何一个时,它将解析 xml 文件并从 xml 文件创建列表视图。我将能够像树结构一样在列表视图上导航。这是一个示例 xml 文件。所以应该这样看

<Prototypes>
<Node>
  <Type>Class</Type>
  <ShapeType>Rectangle</ShapeType>
  <Properties>
    <Property>
      <Type>attributes</Type>
      <View Position="Inside" ShapeType="Transparent"/>
      <Modifiers>
        <Modifier id="0">
          <Type>static</Type>
          <View Bold="false" Italic="true" Prefix="" Suffix="" Underline="false"/>
        </Modifier>
        <Modifier id="1">
          <Type>protected</Type>
          <View Bold="false" Italic="false" Prefix="#" Suffix="" Underline="false"/>
        </Modifier>
        <Modifier id="2">
          <Type>private</Type>
          <View Bold="false" Italic="false" Prefix="-" Suffix="" Underline="false"/>
        </Modifier>
      </Modifiers>
    </Property>
    <Property>
      <Type>operations</Type>
      <View Position="Inside" ShapeType="Transparent"/>
      <Modifiers>
        <Modifier id="0">
          <Type>static</Type>
          <View Bold="false" Italic="true" Prefix="" Suffix="" Underline="false"/>
        </Modifier>
        <Modifier id="1">
          <Type>protected</Type>
          <View Bold="false" Italic="false" Prefix="#" Suffix="" Underline="false"/>
        </Modifier>
        <Modifier id="2">
          <Type>private</Type>
          <View Bold="false" Italic="false" Prefix="-" Suffix="" Underline="false"/>
        </Modifier>
      </Modifiers>
    </Property>
  </Properties>
</Node>
<Edge>
  <Type>Association</Type>
  <LineStyle>Solid</LineStyle>
  <MinAttachedNodes>2</MinAttachedNodes>
  <MaxAttachedNodes>2</MaxAttachedNodes>
  <Heads>
    <Head Head="Tail" headLabel="from"/>
    <Head Head="V" headLabel="to"/>
  </Heads>
</Edge>
<Edge>
  <Type>Generalization</Type>
  <LineStyle>Dashed</LineStyle>
  <MinAttachedNodes>2</MinAttachedNodes>
  <MaxAttachedNodes>2</MaxAttachedNodes>
  <Heads>
    <Head Head="Tail" headLabel="sub class"/>
    <Head Head="Triangle" headLabel="super class"/>
  </Heads>
</Edge>
</Prototypes> 
<Components>
<Nodes>
  <Node Name="Company" Type="Class" id="1">
    <Position x="129.0" y="52.0"/>
    <Properties>
      <Property>
        <Type>attributes</Type>
        <Element>
          <Value>budget</Value>
        </Element>
        <Element>
          <Value>name</Value>
        </Element>
      </Property>
      <Property>
        <Type>operations</Type>
        <Element>
          <Value>Company</Value>
        </Element>
        <Element>
          <Value>getDriverQualification</Value>
        </Element>
      </Property>
    </Properties>
  </Node>
  <Node Name="Driver" Type="Class" id="2">
    <Position x="135.0" y="304.0"/>
    <Properties>
      <Property>
        <Type>attributes</Type>
        <Element>
          <Value>name</Value>
        </Element>
      </Property>
      <Property>
        <Type>operations</Type>
        <Element>
          <Value>getQualification</Value>
        </Element>
      </Property>
    </Properties>
  </Node>
  <Node Name="Vehicle" Type="Class" id="3">
    <Position x="477.0" y="301.0"/>
    <Properties>
      <Property>
        <Type>attributes</Type>
        <Element>
          <Value>registration</Value>
        </Element>
      </Property>
      <Property>
        <Type>operations</Type>
        <Element>
          <Value>Vehicle</Value>
        </Element>
        <Element>
          <Value>getRegistration</Value>
        </Element>
      </Property>
    </Properties>
  </Node>
  <Node Name="Van" Type="Class" id="4">
    <Position x="381.0" y="519.0"/>
    <Properties>
      <Property>
        <Type>attributes</Type>
        <Element>
          <Value>size</Value>
        </Element>
      </Property>
      <Property>
        <Type>operations</Type>
        <Element>
          <Value>Van</Value>
        </Element>
      </Property>
    </Properties>
  </Node>
  <Node Name="Car" Type="Class" id="5">
    <Position x="641.0" y="512.0"/>
    <Properties>
      <Property>
        <Type>attributes</Type>
        <Element>
          <Value>fuelType</Value>
        </Element>
      </Property>
      <Property>
        <Type>operations</Type>
        <Element>
          <Value>Car</Value>
        </Element>
      </Property>
    </Properties>
  </Node>
</Nodes>
<Edges>
  <Edge Name="employs" Type="Association" id="1">
    <Nodes>
      <Node Head="" Label="1" id="1"/>
      <Node Head="V" Label="*" id="2"/>
    </Nodes>
  </Edge>
  <Edge Name="hires" Type="Association" id="2">
    <Nodes>
      <Node Head="" Label="1" id="1"/>
      <Node Head="" Label="*" id="3"/>
    </Nodes>
    <Points>
      <Point id="-1">
        <Position x="524.5" y="83.5"/>
        <Neighbours>1 3</Neighbours>
      </Point>
    </Points>
  </Edge>
  <Edge Name="drives" Type="Association" id="3">
    <Nodes>
      <Node Head="V" Label="*" id="3"/>
      <Node Head="" Label="1" id="2"/>
    </Nodes>
  </Edge>
  <Edge Name="G1" Type="Generalization" id="4">
    <Nodes>
      <Node Head="" Label="" id="4"/>
      <Node Head="Triangle" Label="" id="3"/>
    </Nodes>
  </Edge>
  <Edge Name="G2" Type="Generalization" id="5">
    <Nodes>
      <Node Head="Triangle" Label="" id="3"/>
      <Node Head="" Label="" id="5"/>
    </Nodes>
  </Edge>
</Edges>
</Components>

结果应该在列表视图中,例如;(这是结果的一部分。我还没有定义所有的输出)

•   Class
       ➢    Company
           o    Association
                   •    To Vehicle via hires
                   •    To Driver via  employs
           o    Attributes
                   •    budget
                   •    name
           o    operations
                   •    Company
                   •    getDriverQualification
       ➢    Driver
       ➢    Vehicle
       ➢    Van
       ➢    Car
•   Association
•   Generalization

我寻找你的建议。欢迎所有建议。我并不是真的在这里寻找确切的代码:) 我将对此进行编码,但在开始之前,我试图找到将 xml 文件解析为列表视图的最佳方法。

谢谢

4

0 回答 0