Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the VB.NET XmlReader class

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to use the VB.NET XmlReader class. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

There are two ways to operate XML

1. Use MSXML

MSXML is the parser of XML, and MSXML is a COM-based component, so you need to create an interoperable assembly. The easiest way is to add a reference to the COM component (Microsoft XML,v4.0 (or v3.0 focus v2.6)) in VS. MSXML2 appears in the reference column (when the COM component is imported, the namespace provided for the new assembly is the type library name of the COM component).

two。 Use the System.Xml class

Compared with the msxml class, the System.Xml class has several advantages. First of all, System.Xml is managed code, and you can use it to ensure that all code is secure and type safe. Using COM interoperability adds some overhead, but most importantly, the System.Xml namespace is easy to use and very flexible.

XML in read-write stream format

VB.NET XmlReader does not provide very high memory requirements and provides a very fast, only a few-time read-only cursor to process XML data.

VB.NET XmlWriter can generate XML documents.

Both VB.NET XmlReader and XmlWriter are abstract classes.

Classes derived from XmlReader are XmlNodeReader (using XmlNode as its source rather than a stream), XmlValidatingReader (XmlValidatingReader adds DTD and schema validation to provide validation of data), XmlTextReader (used with TextReader objects in the IO namespace), and XmlTextWriter (used with TextWriter objects in the IO namespace).

II. VB.NET XmlReader class

XmlReader is very similar to SAX. The difference between them * is that SAX is a push model (all XML data must be processed by the application, whether it is needed or not), and XmlReader is a pull model (if you don't need all the data, you don't need to process it).

The code is as follows:

RichTextBox1.Clear (); XmlReader rdr = XmlReader.Create ("book.xml"); while (rdr.Read ()) {if (rdr.NodeType = = XmlNodeType.Text) richTextBox1.AppendText (rdr.Value+ "\ r\ n");}

(1) A XmlReader object is returned using the static method Create ().

(2) the Read () method can enter the next node.

The XmlReader class can also read strongly typed data, which has several ReadValuesAs methods, such as, ReadValueAsDouble, ReadValueAsBoolean, and so on.

Thank you for reading! This is the end of this article on "how to use VB.NET XmlReader classes". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report