Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on 

Help with loading data from one xml file to multiple Listboxes

Hi,

If I have an xml file with the following data. I am tryin to minimize the number of xml files in my project.

<Root>
<CountryTable>
<Country_ID>1</Country_ID>
<Country>BEL</Country>
</CountryTable>
<CountryTable>
<Country_ID>2</Country_ID>
<Country>CAN</Country>
</CountryTable>
<ItemTable>
<Item_ID>1</Item_ID>
<Item>ItemA</Item>
</ItemTable>
<ItemTable>
<Item_ID>2</Item_ID>
<Item>ItemB</Item>
</ItemTable>
</Root>

How do I load Listbox1 with CountryTable data and Listbox2 with ItemTable data?

Currently I ma using the following approach to load the components when they are in separate xml files.


        Dim CountryUser As New DataSet
        CountryUser.ReadXml(Server.MapPath("~/App_Data/CountryUser.xml"))
        C1ACountryUser.DataSource = CountryUser.Tables(0)
        C1ACountryUser.DataMember = "Country"
        C1ACountryUser.DataTextField = "Country"
        C1ACountryUser.DataValueField = "Country_ID"
        C1ACountryUser.DataBind()

Victor
ASP.NET.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
Victor Charles
ASKER CERTIFIED SOLUTION
Avatar of Rose Babu
Rose Babu
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Victor  Charles

ASKER

Thanks, How would i modify the code below to accomodate using the approach above?
For example Item, ItemA and Country are combined in XMLFile.xml as shown in Part B below.

Dim xyz() As String = New String() {"Item", "ItemA", "Country"}

        For i = 0 To 2

            Dim curXYZ = xyz(i)
            Dim MyFix As XDocument = XDocument.Load(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))

            Dim xid As String

            xid = curXYZ & "_ID"

            Dim LargestFixID = (From el In MyFix.Descendants(curXYZ & "Table") Select CInt(el.<xid>.Value)).ToList
            LargestFixID.Sort()

            Dim xtable As String

            xtable = curXYZ & "Table"
            Dim ctrl As Control = MultiView1.FindControl("C1" & curXYZ)
            Dim Txt As String = Nothing
            If TypeOf (ctrl) Is C1ComboBox Then
                Txt = CType(ctrl, C1ComboBox).Text
            End If

            Dim CheckForItemFix = (From el In MyFix.Descendants(xtable).Elements(curXYZ) Select el.Value).ToList


            'Check if value is already in xml files, if not add it to the xml files
            If Not CheckForItemFix.Contains(Txt) Then

                Dim xNew As XElement = New XElement(xtable)

                xNew.Add(New XElement(xid, (LargestFixID.Count() + 1)))

                xNew.Add(New XElement(curXYZ, Txt))

                MyFix.Root.Add(xNew)

                MyFix.Save(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))

                'Prepare variable to add to Link.xml file

                Select Case curXYZ
                    Case "Item"
                        searchIdItem = LargestFixID.Count() + 1
                    Case "ItemA"
                        searchIdItemA = LargestFixID.Count() + 1
                    Case "Country"
                   searchIdCountry = LargestFixID.Count() + 1
                  End Select
            End If


Part B:

<?xml version="1.0" encoding="utf-8" ?>
<Root>
  <CountryTable>
    <Country_ID>1</Country_ID>
    <Country>BEL</Country>
  </CountryTable>
  <CountryTable>
    <Country_ID>2</Country_ID>
    <Country>CAN</Country>
  </CountryTable>
  <ItemTable>
    <Item_ID>1</Item_ID>
    <Item>ItemA</Item>
  </ItemTable>
  <ItemTable>
    <Item_ID>2</Item_ID>
    <Item>ItemB</Item>
  </ItemTable>
 <ItemTableA>
    <ItemA_ID>1</ItemA_ID>
    <ItemA>ItemA</ItemA>
  </ItemTableA>
  <ItemTableA>
    <ItemA_ID>2</Item_ID>
    <ItemA>ItemB</ItemA>
  </ItemTableA>
</Root>
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo