Click here to Skip to main content
15,905,913 members
Home / Discussions / C#
   

C#

 
QuestionRename the File name Pin
Anonymous18-Sep-05 23:42
Anonymous18-Sep-05 23:42 
AnswerRe: Rename the File name Pin
Stefan Troschuetz19-Sep-05 0:29
Stefan Troschuetz19-Sep-05 0:29 
AnswerRe: Rename the File name Pin
Dave Kreskowiak19-Sep-05 5:41
mveDave Kreskowiak19-Sep-05 5:41 
QuestionLog Pin
Gktony18-Sep-05 23:05
Gktony18-Sep-05 23:05 
AnswerRe: Log Pin
enjoycrack19-Sep-05 1:23
enjoycrack19-Sep-05 1:23 
GeneralRe: Log Pin
Gktony19-Sep-05 3:36
Gktony19-Sep-05 3:36 
QuestionGDI+ :How to judge a point in the path. Pin
dreamwinter18-Sep-05 23:01
dreamwinter18-Sep-05 23:01 
QuestionExtracting attribute information from an XML file Pin
Vikram A Punathambekar18-Sep-05 20:41
Vikram A Punathambekar18-Sep-05 20:41 
I'm learning C#, and hit this wall while trying to extract attrib info from an XML file. The method I'm using is
void Button4Click(object sender, System.EventArgs e)
{
    string fileName = "..\\..\\books.xml";
    XmlTextReader tr = new XmlTextReader(fileName);
    listBox1.Items.Clear();
    int countAttribute = 0;
    while(tr.Read())
    {
        if(tr.NodeType == XmlNodeType.Attribute)
        {
            countAttribute++;
            string displayString = tr.Name;
            displayString += tr.Value;
            listBox1.Items.Add(displayString);
        }
    }
    tr.Close();
    MessageBox.Show("Encountered " + countAttribute + " attribute(s)");
}


The XML file indeed contains attribs, and here's a part of it:
<book genre="humor" publicationdate="1897" ISBN="0-863411-58-1">
	<title>Three men in a boat</title>
	<author>
		<first-name>Jerome</first-name>
		<last-name>Jerome</last-name>
	</author>
	<price>4.99</price>
</book>


However, the list is not getting populated and the message box tells me it encountered no attributes at all. Am I doing something wrong? Can somebody please tell me how to get the attribute names and values?

Thanks in advance! Smile | :)

Cheers,
Vikram.

http://www.geocities.com/vpunathambekar

Google talk: binarybandit

After all is said and done, much is said and little is done.

-- modified at 2:41 Monday 19th September, 2005
AnswerRe: Extracting attribute information from an XML file Pin
bpontillo18-Sep-05 22:14
bpontillo18-Sep-05 22:14 
GeneralRe: Extracting attribute information from an XML file Pin
Vikram A Punathambekar18-Sep-05 22:42
Vikram A Punathambekar18-Sep-05 22:42 
GeneralRe: Extracting attribute information from an XML file Pin
bpontillo18-Sep-05 23:18
bpontillo18-Sep-05 23:18 
QuestionCode to flip a window Pin
Amir Harel18-Sep-05 20:29
Amir Harel18-Sep-05 20:29 
QuestionAbt Structure of Text Files Pin
akshayswaroop18-Sep-05 20:14
akshayswaroop18-Sep-05 20:14 
AnswerRe: Abt Structure of Text Files Pin
enjoycrack18-Sep-05 20:31
enjoycrack18-Sep-05 20:31 
AnswerRe: Abt Structure of Text Files Pin
akshayswaroop18-Sep-05 20:35
akshayswaroop18-Sep-05 20:35 
AnswerRe: Abt Structure of Text Files Pin
mav.northwind19-Sep-05 2:53
mav.northwind19-Sep-05 2:53 
AnswerRe: Abt Structure of Text Files Pin
lmoelleb19-Sep-05 20:35
lmoelleb19-Sep-05 20:35 
QuestionFind HyperLinks Pin
A.Grover18-Sep-05 19:47
A.Grover18-Sep-05 19:47 
AnswerRe: Find HyperLinks Pin
enjoycrack18-Sep-05 20:25
enjoycrack18-Sep-05 20:25 
AnswerRe: Find HyperLinks Pin
seee sharp18-Sep-05 23:14
seee sharp18-Sep-05 23:14 
QuestionDataGridBoolColumn - event Pin
JuergenLissmann18-Sep-05 18:54
JuergenLissmann18-Sep-05 18:54 
AnswerRe: DataGridBoolColumn - event Pin
deep718-Sep-05 20:10
deep718-Sep-05 20:10 
QuestionCommunication With ports in Visual.NET Pin
samira forooghi18-Sep-05 18:45
samira forooghi18-Sep-05 18:45 
AnswerRe: Communication With ports in Visual.NET Pin
zon_cpp19-Sep-05 6:08
zon_cpp19-Sep-05 6:08 
AnswerRe: Communication With ports in Visual.NET Pin
zon_cpp19-Sep-05 6:08
zon_cpp19-Sep-05 6:08 

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.