Click here to Skip to main content
16,004,977 members
Home / Discussions / C#
   

C#

 
GeneralRe: Reading an XML file Pin
yonidebest12-Dec-06 2:55
yonidebest12-Dec-06 2:55 
GeneralRe: Reading an XML file Pin
Kent Sharkey12-Dec-06 8:07
staffKent Sharkey12-Dec-06 8:07 
GeneralRe: Reading an XML file Pin
yonidebest12-Dec-06 8:31
yonidebest12-Dec-06 8:31 
GeneralRe: Reading an XML file [modified] Pin
Kent Sharkey12-Dec-06 8:37
staffKent Sharkey12-Dec-06 8:37 
GeneralRe: Reading an XML file [modified] Pin
yonidebest12-Dec-06 14:48
yonidebest12-Dec-06 14:48 
GeneralRe: Reading an XML file Pin
Kent Sharkey13-Dec-06 7:08
staffKent Sharkey13-Dec-06 7:08 
GeneralRe: Reading an XML file Pin
yonidebest13-Dec-06 10:01
yonidebest13-Dec-06 10:01 
AnswerRe: Reading an XML file [modified] Pin
meeram39511-Dec-06 22:17
meeram39511-Dec-06 22:17 
Hi,

There is another way which you can read the values of XML file. Given below the code.

1. In the XML file, add the lines as below:
CityNY name="New York" population=10,000,000 growth=1.2
CityMi name="Miami" population=7,000,000 growth=2.4
2. Open a new class called ReadXMLConfig
3. use the namespace, using System.Xml;
4. Declare the data members as follows :

public class ReadXMLConfig
{
XMLDocument xmlDoc;
private string NYName;
private string NYpop;
private string NYgrowth;
private string MiName;
private string Mipop;
private string Migrowth;
}
5. Type the following in the constructor area:
xmlDoc=new XmlDocument // in the constructor
NYName = null;
NYpop = null;
NYgrowth = null;
MiName=null;
Mipop=null;
migrowth=null;
6. Create a function called LoadXML and type as follows:
public void LoadXML()
{
xmlDoc.Load("XMLFilename");

XmlNodeList elemList;
XmlElement elem;

elemList = xmlDoc.GetElementsByTagName("CityNY");
elem = (XmlElement)elemList[0];
NYName = elem.GetAttribute("name");
NYpop = elem.GetAttribute("population");
NYgrowth = elem.GetAttribte("growth");

elemList = xmlDoc.GetElementsByTagName("CityMi");
elem = (XmlElement)elemList[0];
MiName = elem.GetAttribute("name");
Mipop = elem.GetAttribute("population");
Migrowth = elem.GetAttribte("growth");


}

Call this load function wherever you want.
Hope this will helps.

Cheers



-- modified at 4:24 Tuesday 12th December, 2006

Meeram395

GeneralRe: Reading an XML file Pin
yonidebest12-Dec-06 2:59
yonidebest12-Dec-06 2:59 
QuestionBrowser preview Pin
netJP12L11-Dec-06 10:56
netJP12L11-Dec-06 10:56 
QuestionClickonce - how to Build deliverables once and Deployed universally Pin
tiongbox10011-Dec-06 10:31
tiongbox10011-Dec-06 10:31 
Questioncopy a byte array to a UInt16 array Pin
NYTSX11-Dec-06 9:58
NYTSX11-Dec-06 9:58 
AnswerRe: copy a byte array to a UInt16 array Pin
Guffa11-Dec-06 14:13
Guffa11-Dec-06 14:13 
QuestionCopy File Pin
TAREQ F ABUZUHRI11-Dec-06 9:01
TAREQ F ABUZUHRI11-Dec-06 9:01 
AnswerRe: Copy File Pin
Eric Dahlvang11-Dec-06 10:08
Eric Dahlvang11-Dec-06 10:08 
QuestionCopy File Pin
TAREQ F ABUZUHRI11-Dec-06 8:59
TAREQ F ABUZUHRI11-Dec-06 8:59 
AnswerRe: Copy File Pin
Eric Dahlvang11-Dec-06 9:04
Eric Dahlvang11-Dec-06 9:04 
QuestionJVM in C# Pin
GoLuM_3011-Dec-06 8:13
GoLuM_3011-Dec-06 8:13 
AnswerRe: JVM in C# Pin
Colin Angus Mackay11-Dec-06 8:18
Colin Angus Mackay11-Dec-06 8:18 
GeneralRe: JVM in C# Pin
GoLuM_3011-Dec-06 8:36
GoLuM_3011-Dec-06 8:36 
GeneralRe: JVM in C# Pin
Dan Neely11-Dec-06 8:50
Dan Neely11-Dec-06 8:50 
GeneralRe: JVM in C# Pin
GoLuM_3011-Dec-06 11:22
GoLuM_3011-Dec-06 11:22 
AnswerRe: JVM in C# Pin
Judah Gabriel Himango11-Dec-06 9:06
sponsorJudah Gabriel Himango11-Dec-06 9:06 
GeneralRe: JVM in C# Pin
GoLuM_3011-Dec-06 10:27
GoLuM_3011-Dec-06 10:27 
GeneralRe: JVM in C# Pin
Judah Gabriel Himango11-Dec-06 10:36
sponsorJudah Gabriel Himango11-Dec-06 10:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.