Collect attributes from a XML file by XMLReader

Vso

New Member
I have an XML file as below.\[code\]<BOOK bnumber="1" bname="Book"> <CHAPTER cnumber="1"> <Sentence vnumber="1">This is the sentence 1.</Sentence> <Sentence vnumber="2">This is the sentence 2.</Sentence> <Sentence vnumber="3">This is the sentence 3.</Sentence> </CHAPTER> <CHAPTER cnumber="2"> <Sentence vnumber="1">Hello World 1.</Sentence> <Sentence vnumber="2">Hello World 2.</Sentence> <Sentence vnumber="3">Hello World 3.</Sentence> <Sentence vnumber="4">Hello World 4.</Sentence> </CHAPTER> <CHAPTER cnumber="3"> <Sentence vnumber="1">Good morning 1.</Sentence> <Sentence vnumber="2">Good morning 2.</Sentence> <Sentence vnumber="3">Good morning 3.</Sentence> </CHAPTER></BOOK>\[/code\]What I want is to collect the attributes of "CHAPTER".The goal is to get\[code\]Chapter={"Chapter 1";"Chapter 2","Chapter 3"};\[/code\]Current I use tradition method, \[code\]XmlDocument xdoc = new XmlDocument();xdoc.Load(@"C:\books.xml"); //load the xml file into our documentXmlNodeList nodes = xdoc.SelectNodes(@"//BOOK/CHAPTER[@cnumber='" + chapstring sentences = "";foreach(XmlNode node in nodes) { sentences += node.InnerText + "; ";}\[/code\]but I want to use XMLReader because the XML file is big, I don't want to load it in memory.Thanks for help.
 
Back
Top