Something I must missunderstand about XML...

  • Thread starter Thread starter baramuse
  • Start date Start date
B

baramuse

Hi all


I tried to write a simple XML-based message parser
I just can't get the infos I want from the XML

here is the xml file:
----
<?xml version="1.0" encoding="utf-8" ?>
<message id="00001">
<body>Corps du message de test. Ca donc c'est juste un test de message
</body>
<subject>Sujet test1</subject>
<sender>Moi meme</sender>
</message>
---

and the parser:
r = new XmlTextReader(path + file.Name);
while (r.Read())
{
if (r.NodeType == XmlNodeType.Element)
{
if (r.Name == "message")
msg.Id = r.GetAttribute("id");
else if (r.Name == "subject")
msg.Subject = r.Value;
else if (r.Name == "body")
msg.Body = r.Value;
else if (r.Name == "sender")
msg.Sender = r.Value;
}
}
r.Close();

I get the Id attribut id but none of the values...
Is that a good way to do this ?
Am I totally wrong by doing this?

thx in advance!
 
Also, you may want to take a look into xpath for querying your xml. It's
pretty easy to use and fairly powerful. www.w3schools.com is what I always
use for reference if I need it.
 
Back
Top