Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / July 2003

Tip: Looking for answers? Try searching our database.

Read XML

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul Marrero - 25 Jul 2003 02:24 GMT
I'm sure this has been asked before, but with over 3,000 listings...Anyway,
what I want to do is load an XML file so I can populate the text property of
a label in VB .NET.

The XML file is as follows:

 <orglevels>
      <code>2</code>
      <desc>Tampa Division</desc>
 </orglevels>
 <orglevels>
      <code>3</code>
      <desc>Software Development</desc>
 </orglevels>

I want to read this XML file and display the description ("Desc")  so that
it diplays on a Windows Form.
For example: label.text = orglevels.desc

TIA.
-Paul
Oleg Tkachenko - 27 Jul 2003 11:35 GMT
> I'm sure this has been asked before, but with over 3,000 listings...Anyway,
> what I want to do is load an XML file so I can populate the text property of
[quoted text clipped - 14 lines]
> it diplays on a Windows Form.
> For example: label.text = orglevels.desc

I think XmlSerializer can fit your needs in the most elegant way:

XML doc:
<Organization xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<orglevels>
       <code>2</code>
       <desc>Tampa Division</desc>
  </orglevels>
  <orglevels>
       <code>3</code>
       <desc>Software Development</desc>
  </orglevels>
</Organization>

Plumbing:

namespace Test2 {

    public class Organization {
        [XmlElement("orglevels")]
        public OrgLevel[] orglevels;
        public class OrgLevel {
            public int code;
            public string desc;
        }
    }

    public class Test {
        static void Main(string[] args) {
            XmlSerializer serializer = new XmlSerializer(typeof(Organization));
            //Deserialize organization description   
            Organization org = (Organization)serializer.Deserialize(new
StreamReader("org.xml"));
            foreach (Organization.OrgLevel orglevel in org.orglevels)
                Console.WriteLine("orglevel code: {0}, desc: {1}",
orglevel.code, orglevel.desc);
        }
    }
}

Signature

Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

vector - 28 Jul 2003 21:19 GMT
> I think XmlSerializer can fit your needs in the most elegant way:
>
[quoted text clipped - 36 lines]
>      }
> }

Can XmlSerialization be used in conjunction with some technique to
produce a schema alongside the OrgLevel elements?  For example:

<root>
 <xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:element name="OrgLevel">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="code" type="integer" />
         <xs:element name="desc" type="string" />
       </xs:sequence>
     </xs:complexType>
   </xs:element>
 </xs:schema>

 <OrgLevel>
   <code>2</code>
   <desc>Tampa Division</desc>
 </OrgLevel>
 
 <OrgLevel>
   <code>3</code>  
   <desc>Software Development</desc>
 </OrgLevel>

</root

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.