Xml reading and Parsing in listview in Android?

dawsonapricot

New Member
I am doing simple project which gets a xml file from the source (this is a folder in the application called "diagrams"). So there is a button when I launch the applciation. when you click the button it will take me the source "diagrams" folder. In the diagrams folder, there are xml files. When I choose any of them it will parse the xml file and create the listview from the xml file. and I will be able to navigate on the listview like a tree structure. Here is a sample xml file. So this should be seen like this\[code\]<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>\[/code\]And result should be in the list view like; (this is the part of the result. I haven't defined all the output)\[code\]? 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\[/code\]I look for your suggestions. Please all suggestions are welcomed. I am not really looking for the exact code here :) I will be coding this but before I start, I am trying to find what would be the best way of parsing the xml file into a listview.Thanks
 
Back
Top