Skip to main content
gamedev.net
🔒 Locked

XML variable ?

Started by PCosmin89 2 replies 600+ views
Original Post
PCosmin89
PCosmin89
Greetings everyone, I come yet again with a problem, a noob question to be honest. I'm using C# to get data from an XML table, I managed to get what I need except for
Quote:
<registered unixtime="1037793040">2002-11-20 11:50</registered>
I need to get unixtime, anyone have any ideas on how I get it ? In case it matters, this is the method I am using to get other fields:

while (userReader.Read())
                    {
                        if (userReader.NodeType == XmlNodeType.Element && userReader.Name == "name")
                            while (userReader.Read())
                                if (userReader.NodeType == XmlNodeType.Text)
                                {
                                    totalMembrii++;
                                    numeUser = Convert.ToString(userReader.Value);
                                    break;
                                }

                        if (userReader.NodeType == XmlNodeType.Element && userReader.Name == "playcount")
                            while (userReader.Read())
                                if (userReader.NodeType == XmlNodeType.Text)
                                {
                                    totalMelodii += Convert.ToInt32(userReader.Value);
                                    playCount = Convert.ToInt32(userReader.Value);
                                    break;
                                }

                    }

silvermace
silvermace
Im not really a C# programmer, but surely there's an Attributes collection or something on your XmlNodeType object? if not there should be an accessor named something along the lines of GetAttribute?

[google] ??
PCosmin89
PCosmin89
Thanks, I tried google but I had no idea on what I should search, attributes worked fine, thank you
jbelkus
jbelkus
Check that the NodeType is XmlNodeType.Element and that Name is "registered", you can then pull out attributes using the XmlReader.GetAttribute() method.

MSDN is your buddy:
http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.getattribute.aspx

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.