473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Read XML

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
Nov 11 '05 #1
2 2403
Paul Marrero wrote:
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


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);
}
}
}

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

Nov 11 '05 #2
Oleg Tkachenko <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message news:<#v**************@TK2MSFTNGP11.phx.gbl>...
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);
}
}
}


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>
Nov 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gunnar | last post by:
Hello, I've just written a CPP program that reads integers from a binary file, and used this code while (my_ifstram.read( (char* ) &number, sizeof(int)) { // do something with number } My...
11
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to...
12
by: Steven T. Hatton | last post by:
I know of a least one person who believes std::ifstream::read() and std::ofstream::write() are "mistakes". They seem to do the job I want done. What's wrong with them. This is the code I...
2
by: Sandman | last post by:
Just looking for suggestion on how to do this in my Web application. The goal is to keep track of what a user has and hasn't read and present him or her with new material I am currently doing...
4
by: Ollie Cook | last post by:
Hi, I am having some difficulty with read(2) and interrupting signals. I expect I am misunderstanding how the two work together, so would appreciate some guidance. I am trying to 'time out' a...
6
by: BBM | last post by:
I have an object that has a fairly complex construction sequence, so I have written a dedicated "factory" class that invokes the constructor of my object class (which does nothing but instantiate...
8
by: a | last post by:
I have a struct to write to a file struct _structA{ long x; int y; float z; } struct _structA A; //file open write(fd,A,sizeof(_structA)); //file close
1
by: Jose Reckoner | last post by:
I'm running python 2.3 on Windows XP. Anyone have a quick small script to convert .DT1 and .DEM data to ASCII or some other format? I don't need a viewer. Thanks!
0
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using Visual Studio C# Express. I have successfully made...
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a *...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.