当前位置:网站首页>Introduction to XML III
Introduction to XML III
2022-07-04 13:41:00 【Hua Weiyun】
Xml Basics 03
Supplementary review :
Xml
Extensible markup language
eXtensible Markup Language
A way to store data in simple text format
Xml**** structure
Elements , attribute , Statement , notes
XML**** Document validation
DTD
Schema :XSD framework
Document object model -DOM
XML The tree structure of the file
Xml**** Data analysis
Dom:XPath
Sax:XmlTextReader, XmlTextWriter
Xml And Ado.Net Interaction
XmlNode**** How to select nodes
SelectSingleNode(string)
Choose a match XPath The first of the expressions XmlNode.
SelectNodes(string)
Choose a match XPath The node list of the expression
Apply to :
XmlDocument
XmlElement
XmlAttribute
XPath
Xml Document query language
For from XML Select node set in document
The goal is ( Suppose the current node is book node ) | XPath give an example |
---|---|
Select the current node | . |
Select the parent node | … |
Select all child nodes of the current node | ***** |
choice author Child node | author |
Select the... Of the current node title attribute | @title |
Select all the attributes of the current node | @* |
Select all text nodes of the current node (XmlText) | text() |
Select all nodes with a specific name in the current document , For example, select all author node | //author |
Select all nodes with a specific name and a specific parent node name in the current document , For example, selecting all parent nodes is book, Node is author The node of | //book/author |
Select the node whose value meets the condition , For example, the author selected is Wu Chengen book node | **//book[author= Wu chengen |
Select the node whose attribute meets the condition , For example, choose yes title It's the Red Mansion book node | **//book[@title= ‘ A dream of red mansions ’] |
Xml analysis
DOM : Document based ( object ), Tree structure , When loading, the whole load ( Large memory consumption )
SAX : Based on flow , Load line by line when loading ( It is suitable for parsing a large amount of data )
SAX Pattern parsing Xml
The main constituent classes :
XmlReader( contain XmlTextReader and XmlNodeReader Two classes )
- Only forward , Non cached readers , take XML Data is processed as a stream .
- The memory demand is not great
- There is no need for flexible navigation
- Not based on DOM Read and write functions available in the model
XmlWriter ( contain Xml)
- Is a build for XML Stream provides “ Only forward , Non cache ” The abstract class of the method .
XmlTextReader: Provide for the right to XML Fast file , Only forward access .XmlTextReader Our technology is similar to reading any other file , Open the file first , Read the file , Until the end of the file , Close the file after .
XmlTextReader newReader = new XmlTextReader("filename");newReader.Read(); // Read xml The next node of the file newReader.Read().XmlNodeType()// Find what you need
XmlNodeType Member of an enumeration :
become member | say bright |
---|---|
Attribute | attribute , Such as id=“1” |
Comment | XML notes , Such as <!- - Some comment - -> |
Document | Document object , Express XML The root of the tree |
XmlDeclaration | At the top of the document XML Statement |
Element , EndElement | Start and end elements |
Text | The text content of the element |
Whitespace | Space between marks |
…… | …… |
…… | …… |
Use XmlTextWriter Write XML The process of file is the same as that of file system writing data .
1 Open or create a file .
2 Write data to a file
3 Refresh the data flow to ensure that each action is submitted
4 Close file
XmlTextWrite Use :
1 Create a xml file
XmlTextWriter bookWriter = new XmlTextWriter(“C:\book.xml", Encoding.Default);
2 Write XML
establish XML Statement
bookWriter.WriteStartDocument();
Write node :
bookWriter.WriteStartElement(“Price”);
bookWriter.WriteString(“120”);
bookWriter.WriteEndElement();
perhaps
bookWriter.WriteElementString(" Price ", “120”);
Add attribute
bookWriter.WriteStartElement(“Book”);
bookWriter.WriteAttributeString(“Title”, “ The romance of The Three Kingdoms ”);
bookWriter.WriteEndElement();
3 Refresh the data flow and close the file
bookWriter.Flush();
bookWriter.Close();
Dom And Sax difference
Document object model DOM
DOM Read the whole XML File and store the file in a tree structure .
DOM Create objects that represent everything in the original document , Including elements 、 Text 、 Properties and spaces .
DOM API It's parsing XML Documentation is a very useful method .
SAX analysis
Read and operate XML Faster data 、 A lightweight .
SAX Process it when reading a document , So you don't have to wait for the entire document to be stored before taking action .
Suitable for processing data streams , That is to process data in turn with the flow of data .
summary
Xml
Extensible markup language
eXtensible Markup Language
A way to store data in simple text format
Xml structure
Elements , attribute , Statement , notes
XML Document validation
DTD
Schema :XSD framework
Xml Data analysis
Document object model -DOM
similar Sax:XmlTextReader, XmlTextWriter
Xml And Ado.Net Interaction
DataSet
ReadXml(“xml file ”)
WriteXml(" xml file ");
边栏推荐
- Node の MongoDB 安装
- 【AI系统前沿动态第40期】Hinton:我的深度学习生涯与研究心法;Google辟谣放弃TensorFlow;封神框架正式开源
- Master the use of auto analyze in data warehouse
- 比量子化学方法快六个数量级,一种基于绝热状态的绝热人工神经网络方法,可加速对偶氮苯衍生物及此类分子的模拟
- 上汽大通MAXUS正式发布全新品牌“MIFA”,旗舰产品MIFA 9正式亮相!
- 阿里云有奖体验:用PolarDB-X搭建一个高可用系统
- 7 月数据库排行榜:MongoDB 和 Oracle 分数下降最多
- 干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
- runc hang 导致 Kubernetes 节点 NotReady
- 在 Apache 上配置 WebDAV 服务器
猜你喜欢
[AI system frontier dynamics, issue 40] Hinton: my deep learning career and research mind method; Google refutes rumors and gives up tensorflow; The apotheosis framework is officially open source
[cloud native | kubernetes] in depth understanding of ingress (12)
2022年中国移动阅读市场年度综合分析
Flet教程之 03 FilledButton基础入门(教程含源码)(教程含源码)
Etcd storage, watch and expiration mechanism
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
[leetcode] 96 and 95 (how to calculate all legal BST)
CA: efficient coordinate attention mechanism for mobile terminals | CVPR 2021
A taste of node JS (V), detailed explanation of express module
Talk about the design and implementation logic of payment process
随机推荐
c#数组补充
PostgreSQL 9.1 飞升之路
CA: efficient coordinate attention mechanism for mobile terminals | CVPR 2021
微服务入门
Alibaba cloud award winning experience: build a highly available system with polardb-x
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
In 2022, it will be es2022 soon. Do you only know the new features of ES6?
Samsung's mass production of 3nm products has attracted the attention of Taiwan media: whether it can improve the input-output rate in the short term is the key to compete with TSMC
Runc hang causes the kubernetes node notready
三星量产3纳米产品引台媒关注:能否短期提高投入产出率是与台积电竞争关键
Optional values and functions of the itemized contenttype parameter in the request header
A data person understands and deepens the domain model
When MDK uses precompiler in header file, ifdef is invalid
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
Node の MongoDB 安装
After installing vscode, the program runs (an include error is detected, please update the includepath, which has been solved for this translation unit (waveform curve is disabled) and (the source fil
模块化笔记软件综合评测:Craft、Notion、FlowUs
Cors: standard scheme of cross domain resource request
Besides, rsync+inotify realizes real-time backup of data
Flet教程之 03 FilledButton基础入门(教程含源码)(教程含源码)