loading array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?cmF1bGF2aQ==?=

    loading array

    vs2008 c#
    how can I load an array from XML?

    lets say I have now
    string[] arr = {23,32,45,34,21 ,23,243,45 }
    I want to read the values from XML.

    thanks
  • Chris Shepherd

    #2
    Re: loading array

    raulavi wrote:
    vs2008 c#
    how can I load an array from XML?
    >
    lets say I have now
    string[] arr = {23,32,45,34,21 ,23,243,45 }
    I want to read the values from XML.
    >
    thanks
    What is the format of the XML document?

    You could iterate over the elements however you choose, and then simply keep a
    List<string>, Add the items to the list, and then use ToArray() on the list.

    Chris.

    Comment

    • =?Utf-8?B?cmF1bGF2aQ==?=

      #3
      RE: loading array

      I will detail the problem a little bit more

      our code have many places were we set the array list, I would like to

      use a dinamic approach to load/maintain these arrays...

      whats the best way in XML to do it ?

      we will need to update many customers daily with these arrays.




      "raulavi" wrote:
      vs2008 c#
      how can I load an array from XML?
      >
      lets say I have now
      string[] arr = {23,32,45,34,21 ,23,243,45 }
      I want to read the values from XML.
      >
      thanks

      Comment

      • =?Utf-8?B?cmF1bGF2aQ==?=

        #4
        Re: loading array

        this is a simple sample of the XML.



        <?wpl version="1.0"?>
        <MyArr>
        <MyNumbers>
        <Number>1</Number>
        <Number>2</Number>
        <Number>3</Number>
        </MyNumbers>
        </MyArr>


        this is some code we had to read XML but to a dataset (which I want to avoid )
        DataSet1.ReadXm l("..\form_Prop erties.xml")
        Me.DataBindings .Add(New Binding("Number ", DataSet1,
        "Settings.Numbe rs"))


        I f I use the
        "Chris Shepherd" wrote:
        raulavi wrote:
        vs2008 c#
        how can I load an array from XML?

        lets say I have now
        string[] arr = {23,32,45,34,21 ,23,243,45 }
        I want to read the values from XML.

        thanks
        >
        What is the format of the XML document?
        >
        You could iterate over the elements however you choose, and then simply keep a
        List<string>, Add the items to the list, and then use ToArray() on the list.
        >
        Chris.
        >

        Comment

        • =?UTF-8?B?QXJuZSBWYWpow7hq?=

          #5
          Re: loading array

          raulavi wrote:
          "Chris Shepherd" wrote:
          >raulavi wrote:
          >>vs2008 c#
          >>how can I load an array from XML?
          >>>
          >>lets say I have now
          >>string[] arr = {23,32,45,34,21 ,23,243,45 }
          >>I want to read the values from XML.
          >What is the format of the XML document?
          >>
          >You could iterate over the elements however you choose, and then simply keep a
          >List<string> , Add the items to the list, and then use ToArray() on the list.
          this is a simple sample of the XML.
          >
          <?wpl version="1.0"?>
          <MyArr>
          <MyNumbers>
          <Number>1</Number>
          <Number>2</Number>
          <Number>3</Number>
          </MyNumbers>
          </MyArr>
          >
          >
          this is some code we had to read XML but to a dataset (which I want to avoid )
          DataSet1.ReadXm l("..\form_Prop erties.xml")
          Me.DataBindings .Add(New Binding("Number ", DataSet1,
          "Settings.Numbe rs"))
          This can be done many ways.

          A very traditional way is:

          XmlDocument doc = new XmlDocument();
          doc.Load(@"C:\n umbers.xml");
          List<intlst = new List<int>();
          foreach(XmlElem ent elm in doc.GetElements ByTagName("Numb er"))
          {
          lst.Add(int.Par se(elm.FirstChi ld.Value));
          }

          Arne

          Comment

          • =?Utf-8?B?cmF1bGF2aQ==?=

            #6
            Re: loading array

            thank you Arne I will try it..
            any good links to where I can read more about related items?

            XML to trees?


            "Arne Vajhøj" wrote:
            raulavi wrote:
            "Chris Shepherd" wrote:
            raulavi wrote:
            >vs2008 c#
            >how can I load an array from XML?
            >>
            >lets say I have now
            >string[] arr = {23,32,45,34,21 ,23,243,45 }
            >I want to read the values from XML.
            What is the format of the XML document?
            >
            You could iterate over the elements however you choose, and then simply keep a
            List<string>, Add the items to the list, and then use ToArray() on the list.
            this is a simple sample of the XML.

            <?wpl version="1.0"?>
            <MyArr>
            <MyNumbers>
            <Number>1</Number>
            <Number>2</Number>
            <Number>3</Number>
            </MyNumbers>
            </MyArr>


            this is some code we had to read XML but to a dataset (which I want to avoid )
            DataSet1.ReadXm l("..\form_Prop erties.xml")
            Me.DataBindings .Add(New Binding("Number ", DataSet1,
            "Settings.Numbe rs"))
            >
            This can be done many ways.
            >
            A very traditional way is:
            >
            XmlDocument doc = new XmlDocument();
            doc.Load(@"C:\n umbers.xml");
            List<intlst = new List<int>();
            foreach(XmlElem ent elm in doc.GetElements ByTagName("Numb er"))
            {
            lst.Add(int.Par se(elm.FirstChi ld.Value));
            }
            >
            Arne
            >

            Comment

            Working...