I’m trying to populate an xml file into a Delphi ListView1, then “group” all the [items and subitems] by a [tag] defined in the xml file under the Category section,
I’m trying to make my program have a “tag” system so similar software will be grouped by a common tag, I’m open to suggestions if its not possible with listview then I can use other components to like VirtualStringTree, easylistview ..etc, this program is for my personal use, I’m just curious from a learning point of view since I have seen no other examples on how to accomplish this.
so for the xml listed below it should look like
ListView1
TAG1 [Each tag name in the category, this would be a group]
- New Item 1 <- Category name
-Copy of File <- subitem software name
- bin [This is another category but it has TAG1 so group it with TAG1 items]
TAG4 [Each tag name in the category, this would be a group]
- New Item 1 <-this is the same as TAG1, add it to the TAG4 group since its in tags]
-Copy of File <- subitem software of category
here is a sample of my xml file.
file.xml
<Category>
<Category name="New Item 1" Tags="TAG1 TAG4"/>
<Software name="Copy of File" Tags="">
<PathCache>data\cache\945.ico</PathCache>
<PathExe>$Drive\Development\file.exe</PathExe>
</Software>
<Category name="bin" Tags="TAG1">
<Software name="Copy of File" Tags="">
<PathCache>data\cache\947.ico</PathCache>
<PathExe>$Drive\Development\file.exe</PathExe>
</Software>
<Software name="softwaretitle" Tags="">
<PathCache>data\cache\946.ico</PathCache>
<PathExe>$Drive\Development\test.exe</PathExe>
</Software>
</Category>
</Category>
I added the tags=”” section to the Category section in the xml file, I can rewrite it if needed to
<Category name="New Item 1"/>
<Tags>Tag1 Tag4</tag>
First you should better organize your XML file, to at least this (I suggest you use Notepad++ to indent your XML):
After you have a normalized XML, you can convert it into Delphi classes using XMLDataBinding (File/New/Other/XML/XMLDataBinding), choosing your Categories.xml file.
With the XML mapped to Delphi classes, you can easily walk through the XML data.
Example (Delphi XE):
Hope this helps you!