Read an xml and show it in a listbox

0

What I want is to show it from a listbox the code that I show you in the image to forgive but I can not put it as a code because otherwise the labels are not shown. And I want to show the description and the name of the class.

Code xml

<?xml version="1.0" encoding="UTF-8"?>
<furnidata>
<roomitemtypes>
    <furnitype id="13" classname="shelves_norja">
        <revision>61856</revision>
        <defaultdir>0</defaultdir>
        <xdim>1</xdim>
        <ydim>1</ydim>
        <partcolors>
            <color>#ffffff</color>
            <color>#F7EBBC</color>
        </partcolors>
        <name>Beige Bookcase</name>
        <description>For nic naks and books.</description>
        <adurl/>
        <offerid>5</offerid>
        <buyout>1</buyout>
        <rentofferid>-1</rentofferid>
        <rentbuyout>0</rentbuyout>
        <bc>1</bc>
        <excludeddynamic>0</excludeddynamic>
        <customparams/>
        <specialtype>1</specialtype>
        <canstandon>0</canstandon>
        <cansiton>0</cansiton>
        <canlayon>0</canlayon>
        <furniline>iced</furniline>
    </furnitype>
<roomitemtypes>
<furnidata>
    
asked by Perl 26.07.2016 в 20:55
source

3 answers

1

You could help with linq to xml to parse the xml and take the data from the nodes loading an entity that you can assign the Datasource of the listbox

LINQ To XML Tutorials with Examples

Basic Queries (LINQ to XML) (C #)

It hurts that you have published the xml as an image and also without giving it a format that facilitates the analysis of the dependence of the tags

What I do not see is that node you have these code that you want to list in the control

    
answered by 26.07.2016 / 21:55
source
0

You'll have to create a class with the corresponding attributes that the XML has

using System.Xml.Serialization;

string xml = ("xml");
XmlSerializer xmlConverter = new XmlSerializer(typeof(claseXML));
claseXML datos = (claseXML)xmlConverter.Deserialize(xml);
    
answered by 26.07.2016 в 21:02
0

If all you want is to show an XML file in a ListBox. Use the following code. First you must read the XML file you need.

//Aquí pones la ubicación del archivo XML
string pathForXML = "rutaXML/archivo.xml";
//Cargas un fileStream con los siguientes parámetros.
FileStream fileStream = new FileStream(pathForXML, FileMode.Open, FileAccess.Read);
//Creas un streamReader el cuál contiene el XML leído.
StreamReader fileRead = new StreamReader(fileStream);
//Ahora recorremos el archivo leído línea por línea y lo agregamos al listBox
 string line = "";
        while (fileRead.Peek() != -1)
        {
            line = fileRead.ReadLine();

            if (!string.IsNullOrEmpty(line))
            {
                listBox.Items.Add(line);
            }
        }
//No podemos olvidar cerrar los Stream.
fileRead.Close();
fileStream.Close();

It's that simple to read an XML file and you have all the corresponding indentation.

    
answered by 26.08.2016 в 15:25