C # How to compare the two methods of reading XML documents? Let's first take a look at the comparison between XMLTextReader and XmlDocument reading XML files:
C # Read the XML document. The XMLTextReader class contained in the System. XML namespace Of the. NET Framework can quickly read data from XML files without having to have high requirements on System resources. The
Xml
XmlTextReader classes contained in the System.Xml namespace of the. NET Framework do not require high system resources to quickly read data from an XML file. You can use the XmlTextReader class to read data from an XML file and convert it to HTML format to output in a browser.
Before reading this article, readers need to know some basic knowledge: XML, HTML, C # programming language, and. NET in particu
I saw an article on the Internet and tried it myself. As a result, XMLTextReader is faster!
The XMLTextReader class contained in the System. XML namespace Of the. NET Framework can quickly read data from XML files without high requirements on System resources. The XMLTextReader class can be used to read data from an XML file and convert it to HTML format for out
XmlTextReader is used for fast forward-only read XML.
The XmlTextReader namespace is:
System.Xml
application Example
The code is as follows
Copy Code
XmlTextReader reader = new XmlTextReader (xmlfragment, xmlnodetype.element, NULL);while (reader. Read ()){if (reader. NodeType = = XmlNodeT
C # XmlTextWriter and XmlTextReader read and write XML files,
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml;namespace Xml{class Program{static void Main(string[] args){// XmlTextWriter writes a fileXmlTextWriter writeXml = new XmlTextWriter(@c:MyXml.xml,Encoding.UTF8);writeXml.WriteStartDocument(false);writeXml.WriteStartElement(NetWork);WriteXml. WriteComment (network configuration informa
This article introduces three basic XML application instances to help you quickly enter the XML programming world. Examples include: using XML in. net, reading XML files, and inserting data into XML documents.
Use XML in. net
If msxml3 is used, using XML in. NET applications is quite simple. It doesn't matter if you have never touched msxml3 in real time. You will find it easy to use the classes provided by the. NET platform.
There are two main APIs that can be used to access data created in XM
Xmltextreader is a stream-based XML reader similar to sax. Unlike sax, Sax adopts the PUSH model push mode and xmltextreader adopts the PULL model.ProgramDevelopers can process data more selectively. The following is a simple example:
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1 String Xmlstr = " " 1.0 \ " Encoding = \ " UTF -
, it uses the PUSH model to trigger an event, however, we must write the processing programs for these events, which is very inflexible and troublesome.
. NET uses the implementation scheme based on the "pull" model. When traversing a document, the "pull" model will pull the part of the document that is interested from the reader without triggering events, allow us to access documents in a programmatic manner, which greatly improves flexibility. In terms of performance, the "pull" model can be u
How to read XML data from a stream
This example illustrates how to use the xmltextreader class to read XML from a stream. Streams may come from different sources, such as byte streams from servers, files, or textreader.
Note: This example shows how to continue reading the XML topic from a file.
VB readxmlstream. aspx
[Running example
has a one-way forward, read-only, and tag trigger nature, this is, after all, on the premise of using the Xml Dom, that is, the Document tree (called by the LoadXml method) must be constructed.
C # code
XmlDocument dom = new XmlDocument ();
Dom. Load ("data. xml ");
XPathNavigator nav = dom. CreateNavigator ();
Nav. MoveToRoot ();
String xpath = @ "// Rows [OneColumn = 'somevalue']";
XPathNodeIterator ite = nav. Select (xpath, null );
While (ite. MoveNext ())
{
// Handle i
system. XML. XSL to include classes related to XML operations.
-The system. xml namespace contains some of the most important XML classes. The most important class is related to the read/write operations of XML documents. These classes include four read-related classes and two write-related classes. They are xmlreader, xmltextreader, xmlvalidatingreader, xmlnodereader, xmlwriter, and xmltextwriter. This article will focus on these classes, because th
classes that can analyze, verify, and operate XML data using readers, writers, and components that comply with the W3C DOM requirements. The following list contains the main classes in the XML namespace:XmlNode is an important abstract class. Every node in the DOM tree should be sent by it.XmlDocument class implements W3C Document Object Model Level 1 core and core DOM Level 2.The XmlTextReader class provides fast, non-cache, and inbound read-only ac
, it uses the PUSH model to trigger an event, however, we must write the processing programs for these events, which is very inflexible and troublesome.
. NET uses the implementation scheme based on the "pull" model. When traversing a document, the "pull" model will pull the part of the document that is interested from the reader without triggering events, allow us to access documents in a programmatic manner, which greatly improves flexibility. In terms of performance, the "pull" model can be u
This article mainly introduces the example of. net reading and writing xml documents. For more information, see the example of. net reading and writing xml documents. For more information, see
1. XML-related namespaces in the. Net Framework
System. XmlIt contains some classes related to the read/write operations of XML documents, including XmlReader, XmlTextReader, XmlValidatingReader, XmlNodeReader, XmlWriter, XmlTextWriter, and XmlNode. its sub-cla
1. XML-related namespaces in the. Net Framework
System. XmlIt contains some classes related to the read/write operations of XML documents, including XmlReader, XmlTextReader, XmlValidatingReader, XmlNodeReader, XmlWriter, XmlTextWriter, and XmlNode. Its sub-classes include: xmlDocument, XmlDataDocument, XmlDocumentFragment) and other classes.
System. Xml. SchemaContains classes related to the XML schema, including XmlSchema, XmlSchemaAll, XmlSchemaXPa
This article introduces three basic XML application instances to help you quickly enter the XML programming world. Examples include: using XML in. NET, reading XML files, and inserting data into XML documents.
Use XML in. NET
If MSXML3 is used, using XML in. NET applications is quite simple. It doesn't matter if you have never touched MSXML3 in real time. You will find it easy to use the classes provided by the. NET platform.
There are two main APIs that can be used to access data created in XML
One. XML-related namespaces in the NET Framework
System.XmlContains some classes related to the read and write operations of XML documents: XmlReader, XmlTextReader, XmlValidatingReader, XmlNodeReader, XmlWriter, XmlTextWriter, and XmlNode (its subclasses include: XmlDocument, XmlDataDocument, XmlDocumentFragment) and other classes.
System.Xml.SchemaContains classes related to XML schemas, which include classes such as XmlSchema, Xmlschemaall, Xmlsc
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.