tailieunhanh - Professional Visual Basic 2010 and .neT 4 phần 4

Trong trường hợp này, đối tượng XmlReader được tạo ra bỏ qua không gian màu trắng mà nó gặp, cũng như các ý kiến XML. Các thiết lập này, một khi thành lập với đối tượng XmlReaderSettings, sau đó được liên kết với các đối tượng XmlReader thông qua phương thức Create của nó | 356 I CHAPTER 9 USING XML WITH VISUAL BASIC In this case the XmlReader object that is created ignores the white space that it encounters as well as any of the XML comments. These settings once established with the XmlReaderSettings object are then associated with the XmlReader object through its Create method. Traversing XML Using XmlReader An application can easily use XmlReader to traverse a document that is received in a known format. The document can thus be traversed in a deliberate manner. You just implemented a class that serialized arrays of movie orders. The next example takes an XML document containing multiple XML documents of that type and traverses them. Each movie order is forwarded to the movie supplier via fax. The document is traversed as follows Read root element MovieOrderDump Process each FilmOrderList element Read multiFilmOrders element Process each FilmOrder Send fax for each movie order here The basic outline for the program s implementation is to open a file containing the XML document to parse and to traverse it from element to element Dim myXmlSettings As New XmlReaderSettings Using readMovieInfo As XmlReader fileName myXmlSettings MovieOrderDump Do While True Process FilmOrder elements here Loop MovieOrderDump End Using Code snippet from FilmOrdersReader2 The preceding code opened the file using the constructor of XmlReader and the End Using statement takes care of shutting everything down for you. The code also introduced two methods of the XmlReader class ReadStartElement String This verifies that the current node in the stream is an element and that the element s name matches the string passed to ReadStartElement. If the verification is successful then the stream is advanced to the next element. ReadEndElement This verifies that the current element is an end tab and if the verification is successful then the stream is advanced to the next .

TỪ KHÓA LIÊN QUAN