当前位置:网站首页>Introduction to XML I
Introduction to XML I
2022-07-04 13:41:00 【Hua Weiyun】
Xml Basics 01
Concept :
Extensible markup language , It is a way to store data in simple text format . Can be used for Serialization deserialization ( Serialization is done by converting objects into byte streams , To store or transfer objects to memory , The process of a database or file . The main purpose is to save the state of the object , Include the data of the object , So that the object can be rebuilt when needed . The reverse process is called Deserialization .)
xml The elements of - element:
A pair of angle brackets and angle bracket slashes together form a basic element . for example <> </>, Internally xml Label marking of . In the middle of the angle brackets is the content .
Such as : <book> Journey to the west </book>
<title> Journey to the west </title>
<auther> Wu chengen </auther>
Tags can have inclusive relationships , Nested relationships ( However, it is not recommended , The code is too complex to read )
xml Elements and attributes of
attribute : <book title=‘ Journey to the west ’>
</book>
The difference between elements and attributes :
It is also the way of storing data
Not much difference
Elements cannot describe complex objects
xml Statement of
Declaration file format , edition , codec .
<?xml version="1.0"?><?xml version="1.0" encoding="utf-8" ?><?xml version="1.0" encoding="GBK" ?>xml Notes
Annotation symbols
<!-- -->xml Structure
Xml It provides a structured way to organize data , Unlike a relational database .
Xml Data is organized hierarchically , It's kind of similar windows explorer Folders and files in .
Every document must have a root element , It contains all elements and text data .( That is, there must be a root tag element , Other tag elements are contained by it )
<?xml version="1.0"?><books> <book></book></books><!-- It's legal ->xml The namespace of
That is to say xml Name a name .
For example, the following table :
<?xml version="1.0"?><books xmlns:myNS="123123"> <book></book></books>xml The rules of
1. There must be a declaration statement
<? xml version=“1.0” ?>
2. Yes and only 1 A root element
3. Every element has a closed tag
4. There are no overlapping elements — All child elements must be completely nested within the parent element
5. All attributes must be enclosed in quotation marks
DTD Document definition type
It is not allowed to specify the data type of elements and attributes ( Yes xml The provisions of the document are binding )
schema
frequently-used XSD XML Schema Deinition language
stay .net Also known as XML framework , You can specify the data structure of elements and attributes , With .xsd File storage
Namespace :
http://www.w3.org/2001/XMLSchema Root element : <schema></schema>
<?xml version="1.0"encoding="utf-8"?><xs:schema id="SchemaBooks" targetNamespace="http://tempuri.org/SchemaBooks.xsd" elementFormDefault="qualified" xmins="http://tempuri.org/SchemaBooks.xsd" xmlns:mstns="http://tempuri.org/SchemaBooks.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Books"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="Book"> <xs:complexType> <xs:sequence> <xs:element name="title"type="xs:string"/> <xs;element name="price"type="xs:decimal"/> </xs;sequence> </xs:complexType> </xs:element> </xs;choice> </xs:complexType> </xs:element></xs:schema><!--schema Document root path ( Elements )element node choice complex junction maxOccurs The number of nodes is limited unbounded Is there a limit complexType Specify the element type under this label ->xml And xsd relation
stay vs in , Can pass
System.Data.DataSet ds = new System.Data.DataSet();ds.ReadXml("");ds.WriteXmlSchema("");// Can be xml The file is read and converted to xsd file xsd Several common defaults for :
xmlns:xs=http://www.w3.org/2001/XMLSchema
schema The specification defines the namespaces of some basic data types
targetNamespace=http://tempuri.org/SchemaBookStore.xsd
The schema Of the namespace of URI quote .
xmlns=http://tempuri.org/SchemaBookStore.xsd
Ben XSD Namespace
xmlns:mstns=http://tempuri.org/SchemaBookStore.xsd
Ben XSD Namespace , The prefix name is mstns
Document object model
Document Object Model, DOM
Based on the object ( Based on trees )( Suitable for object extraction, etc )
SAX
Simple API for XML
Based on flow 、 Push model ( Better performance , It is more suitable for reading and parsing data )
DOM Document object model main classes
XmlNode: Express XML A single node in the document .
XmlDocument: Express XML file , Inherited from XmlNode .
XmlElement: Represents an element .
XmlAttribute Represents an attribute
XmlText: Represents the text content of the element .
XmlComment Express XML Content of notes .
XmlNodeList Represents a collection of nodes .
XmlNode.ChildNodes - Returns a that contains all children of the node XmlNodeList.
XmlNode.SelectNodes - Return contains matches XPath Of the node set queried XmlNodeList
XmlDocument Use
Definition ****XmlDocument
XmlDocument document = new XmlDocument();
load XMl file
document.Load(“XML file ”);
Namespace
using System.Xml;
Common properties :
FirstChild Get the first child of the node . ( Inherited from XmlNode.)
DocumentElement Get the root of the document XmlElement.
Common methods
Load()
Save()
Get root node
document.FirstChild
Get the root element
document.DocumentElement
About XmlNode Several important attributes of
FirstChild
LastChild
HasChildNodes
ParentNode
NextSibling
Use DOM establish xml file
Create nodes :
XmlDocument**** Method
CreateNode node
CreateElement Elements
CreateAttribute attribute
CreateTextNode Content
CreateComment notes
Insert node :
XmlNode**** Method
AppendChild Final addition
InsertAfter Add before
InsertBefore Add
Delete node :
XmlNode Method
RemoveAll Delete all
RemoveChild Delete a
RemoveAttribute Delete a property
边栏推荐
- Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
- Web知识补充
- 敏捷开发/敏捷测试感受
- After the game starts, you will be prompted to install HMS core. Click Cancel, and you will not be prompted to install HMS core again (initialization failure returns 907135003)
- Optional values and functions of the itemized contenttype parameter in the request header
- [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
- 面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
- jsonp
- CA:用于移动端的高效坐标注意力机制 | CVPR 2021
- 洞见科技解决方案总监薛婧:联邦学习助力数据要素安全流通
猜你喜欢

Reptile exercises (I)

Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation

After the game starts, you will be prompted to install HMS core. Click Cancel, and you will not be prompted to install HMS core again (initialization failure returns 907135003)

【云原生 | Kubernetes篇】深入了解Ingress(十二)

SQL statement syntax error in test SQL statement deletion in eclipse linked database

JVM系列——栈与堆、方法区day1-2

【AI系统前沿动态第40期】Hinton:我的深度学习生涯与研究心法;Google辟谣放弃TensorFlow;封神框架正式开源

《预训练周刊》第52期:屏蔽视觉预训练、目标导向对话

CTF竞赛题解之stm32逆向入门
![[cloud native | kubernetes] in depth understanding of ingress (12)](/img/34/67eae1e5df89bb0a356a1c29a5e007.png)
[cloud native | kubernetes] in depth understanding of ingress (12)
随机推荐
Etcd 存储,Watch 以及过期机制
数据库锁表?别慌,本文教你如何解决
SQL statement syntax error in test SQL statement deletion in eclipse linked database
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
MDK在头文件中使用预编译器时,#ifdef 无效的问题
PostgreSQL 9.1 飞升之路
高效!用虚拟用户搭建FTP工作环境
Read the BGP agreement in 6 minutes.
Apache server access log access Log settings
Xue Jing, director of insight technology solutions: Federal learning helps secure the flow of data elements
C#/VB. Net to add text / image watermarks to PDF documents
Reinforcement learning - learning notes 1 | basic concepts
AI painting minimalist tutorial
C#基础补充
jsonp
Talk about the design and implementation logic of payment process
求解:在oracle中如何用一条语句用delete删除两个表中jack的信息
从0到1建设智能灰度数据体系:以vivo游戏中心为例
BackgroundWorker用法示例