|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Dec 2001
Città: Lecce
Messaggi: 3936
|
[C#] XmlReader
Mi serve una classe che legga un file xml e mi stampi i valori degli elementi in un form, ho preso questo esempio dall'msdn
Codice:
lass Program
{
static void Main(string[] args)
{
XmlReader reader = XmlReader.Create("config.xml");
while (reader.Read())
{
if (reader.IsStartElement())
{
if (reader.IsEmptyElement)
Console.WriteLine("<{0}/>", reader.Name);
else
{
Console.Write("<{0}> ", reader.Name);
reader.Read(); // Read the start tag.
if (reader.IsStartElement()) // Handle nested elements.
Console.Write("\r\n<{0}>", reader.Name);
Console.WriteLine(reader.ReadString()); //Read the text content of the element.
}
}
}
Console.ReadLine();
}
}
Il file XML è questo: Codice:
<?xml version="1.0"?> <connessioni> <destinazione> <db>cet</db> <host>127.0.0.1</host> <user>utente postgres</user> <password>psw postgres</password> </destinazione> <sorgente> <db>cet</db> <user>nome utente</user> <password>psw</password> </sorgente> </connessioni> <connessioni> <destinazione> <host> 127.0.0.1 <user> utente postgres <password> psw postgres <sorgente> <db>cet <user> nome utente <password> psw come potete notare la terza riga è vuota senza stampare il corrispondente valore, come mai?!? Ultima modifica di DarkSiDE : 16-02-2007 alle 12:01. |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 08:12.



















