当前位置:网站首页>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 ");
边栏推荐
- Solution: how to delete the information of Jack in two tables with delete in one statement in Oracle
- 聊聊支付流程的设计与实现逻辑
- Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务
- Cors: standard scheme of cross domain resource request
- 使用 NSProxy 实现消息转发
- XML入门一
- "Tips" to slim down Seurat objects
- The old-fashioned synchronized lock optimization will make it clear to you at once!
- CANN算子:利用迭代器高效实现Tensor数据切割分块处理
- 实时云交互如何助力教育行业发展
猜你喜欢
Is the outdoor LED screen waterproof?
强化学习-学习笔记1 | 基础概念
Read the BGP agreement in 6 minutes.
Three schemes to improve the efficiency of MySQL deep paging query
Meituan Ali's Application Practice on multimodal recall
《预训练周刊》第52期:屏蔽视觉预训练、目标导向对话
Practice: fabric user certificate revocation operation process
Efficient! Build FTP working environment with virtual users
Dgraph: large scale dynamic graph dataset
数据库锁表?别慌,本文教你如何解决
随机推荐
用fail2ban阻止密码尝试攻
Oracle 被 Ventana Research 评为数字创新奖总冠军
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
Optional values and functions of the itemized contenttype parameter in the request header
[cloud native | kubernetes] in depth understanding of ingress (12)
AI 绘画极简教程
Detailed explanation of mt4api documentary and foreign exchange API documentary interfaces
【AI系统前沿动态第40期】Hinton:我的深度学习生涯与研究心法;Google辟谣放弃TensorFlow;封神框架正式开源
Read the BGP agreement in 6 minutes.
Is the outdoor LED screen waterproof?
Rsyslog配置及使用教程
WPF双滑块控件以及强制捕获鼠标事件焦点
Cors: standard scheme of cross domain resource request
go-zero微服务实战系列(九、极致优化秒杀性能)
再说rsync+inotify实现数据的实时备份
Reading cognitive Awakening
MySQL three-level distribution agent relationship storage
Two dimensional code coding theory
实战:fabric 用户证书吊销操作流程
PostgreSQL 9.1 飞升之路