Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Loading controls from xml file

Loading controls from xml file

Scheduled Pinned Locked Moved LINQ
helpxmlquestionannouncement
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Baeltazor
    wrote on last edited by
    #1

    hi all, i know hot to write to xml files, but i'm having trouble doing what i need to do and can;t find adequite info on this type of problem. Here's one xml file below:

    <?xml version="1.0" encoding="utf-8"?>
    <controls>
    <Label Content="Double-click to edit." Location="258, 178" Size="101, 13" ForeColor="-1" />
    <LinkLabel Content="Double-click to edit." Location="532, 133" Size="101, 13" LinkColor="-1" />
    <LinkLabel Content="Double-click to edit." Location="424, 212" Size="101, 13" LinkColor="-1" />
    <Label Content="Double-click to edit." Location="282, 89" Size="101, 13" ForeColor="-1" />
    <Label Content="Double-click to edit." Location="528, 178" Size="101, 13" ForeColor="-1" />
    <LinkLabel Content="Double-click to edit." Location="528, 133" Size="101, 13" LinkColor="-1" />
    <LinkLabel Content="Double-click to edit." Location="528, 149" Size="101, 13" LinkColor="-1" />
    <Label Content="Double-click to edit." Location="528, 164" Size="101, 13" ForeColor="-1" />
    </controls>

    ... And what I need to do once I've opened this file in my app is:

    foreach(control in XmlFile)
    {
    // do something...
    }

    Can somebody please help me out with this? I'd appreciate any help at all. Thank you Bael

    D 1 Reply Last reply
    0
    • B Baeltazor

      hi all, i know hot to write to xml files, but i'm having trouble doing what i need to do and can;t find adequite info on this type of problem. Here's one xml file below:

      <?xml version="1.0" encoding="utf-8"?>
      <controls>
      <Label Content="Double-click to edit." Location="258, 178" Size="101, 13" ForeColor="-1" />
      <LinkLabel Content="Double-click to edit." Location="532, 133" Size="101, 13" LinkColor="-1" />
      <LinkLabel Content="Double-click to edit." Location="424, 212" Size="101, 13" LinkColor="-1" />
      <Label Content="Double-click to edit." Location="282, 89" Size="101, 13" ForeColor="-1" />
      <Label Content="Double-click to edit." Location="528, 178" Size="101, 13" ForeColor="-1" />
      <LinkLabel Content="Double-click to edit." Location="528, 133" Size="101, 13" LinkColor="-1" />
      <LinkLabel Content="Double-click to edit." Location="528, 149" Size="101, 13" LinkColor="-1" />
      <Label Content="Double-click to edit." Location="528, 164" Size="101, 13" ForeColor="-1" />
      </controls>

      ... And what I need to do once I've opened this file in my app is:

      foreach(control in XmlFile)
      {
      // do something...
      }

      Can somebody please help me out with this? I'd appreciate any help at all. Thank you Bael

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      Maybe something like this?

      XDocument xdc = XDocument.Load("YourFileHere");

      var controls = xdc.Elements("controls");

      foreach (var item in controls)
      {
      if (item.Name == "Label")
      {
      lbl = new System.Windows.Forms.Label();
      lbl.Text = item.Attribute("Content").Value
      }
      else if(item.Name == "LinkLable"){
      //create a link lable
      }
      //and so on
      }

      modified on Sunday, February 7, 2010 12:11 PM

      B 1 Reply Last reply
      0
      • D Dan Mos

        Maybe something like this?

        XDocument xdc = XDocument.Load("YourFileHere");

        var controls = xdc.Elements("controls");

        foreach (var item in controls)
        {
        if (item.Name == "Label")
        {
        lbl = new System.Windows.Forms.Label();
        lbl.Text = item.Attribute("Content").Value
        }
        else if(item.Name == "LinkLable"){
        //create a link lable
        }
        //and so on
        }

        modified on Sunday, February 7, 2010 12:11 PM

        B Offline
        B Offline
        Baeltazor
        wrote on last edited by
        #3

        Oops, sorry. I misread one of the statements in your answer. With the part where you wrote: lbl.Text = "Doubble click here..."; ... What I actually need is the value of the controls corresponding "Content" attribute. Because the text inside the Content attribute is not always going to be "Double click to edit...".

        D 1 Reply Last reply
        0
        • B Baeltazor

          Oops, sorry. I misread one of the statements in your answer. With the part where you wrote: lbl.Text = "Doubble click here..."; ... What I actually need is the value of the controls corresponding "Content" attribute. Because the text inside the Content attribute is not always going to be "Double click to edit...".

          D Offline
          D Offline
          Dan Mos
          wrote on last edited by
          #4

          Yep. My Bad. I was in a hurry. Look at the modified version :-D

          B 1 Reply Last reply
          0
          • D Dan Mos

            Yep. My Bad. I was in a hurry. Look at the modified version :-D

            B Offline
            B Offline
            Baeltazor
            wrote on last edited by
            #5

            YAY It's working now lol Thank you so much for helping me :D :cool::thumbsup:

            D 1 Reply Last reply
            0
            • B Baeltazor

              YAY It's working now lol Thank you so much for helping me :D :cool::thumbsup:

              D Offline
              D Offline
              Dan Mos
              wrote on last edited by
              #6

              you're welcome

              B 1 Reply Last reply
              0
              • D Dan Mos

                you're welcome

                B Offline
                B Offline
                Baeltazor
                wrote on last edited by
                #7

                I hope i didn't make you late for anything

                D 1 Reply Last reply
                0
                • B Baeltazor

                  I hope i didn't make you late for anything

                  D Offline
                  D Offline
                  Dan Mos
                  wrote on last edited by
                  #8

                  nope nothing like that(just the work phone was ringing while I tried to finish my "answer")

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups