XML基础知识

XML基础知识与应用实战 本文还有配套的精品资源,点击获取 简介:XML是一种用于标记数据的语言,适用于数据交换和配置等领域。本教程深入解析XML的基础结构、Schema验证、DOM解析、XSLT转换及数据岛的概念,提供系统的学习路径和实例练习,帮助读者从基础到应用层面全面掌握XML技术。 1. XML基础知识介绍 1.1 XML的定义和用途 1.1.1 XML是什么 XML... 阅读详情

大部分内容来自http://www.w3schools.com。

本文主要是个人学习笔记,将替代手写的笔记。以此记录自己的学习过程,记录不懂的,可以逐渐增加新知识点。


What is XML?

  • XML stands for EXtensible Markup Language
  • XML is a markup language much like HTML
  • XML was designed to carry data, not to display data
  • XML tags are not predefined. You must define your own tags
  • XML is designed to be self-descriptive
  • XML is a W3C Recommendation

The Difference Between XML and HTML

XML is not a replacement for HTML.

XML and HTML were designed with different goals:

  • XML was designed to transport and store data, with focus on what data is
  • HTML was designed to display data, with focus on how data looks

HTML is about displaying information, while XML is about carrying information.

An Example XML Document

XML documents use a self-describing and simple syntax:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

The first line is the XML declaration. It defines the XML version (1.0) and the encoding used (ISO-8859-1 = Latin-1/West European character set).

The next line describes the root element of the document (like saying: "this document is a note"):

The next 4 lines describe 4  child elements  of the root (to, from, heading, and body):

XML Documents Form a Tree Structure

DOM node tree
<bookstore>
  <book category="COOKING">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
  </book>
  <book category="CHILDREN">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book category="WEB">
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</bookstore>


XML Syntax Rules

All XML Elements Must Have a Closing Tag

In XML, it is illegal to omit the closing tag. All elements  must  have a closing tag:

XML Tags are Case Sensitive

XML tags are case sensitive. The tag <Letter> is different from the tag <letter>.

XML Elements Must be Properly Nested

In XML, all elements  must  be properly nested within each other:
<b><i>This text is bold and italic</i></b>

In the example above, "Properly nested" simply means that since the <i> element is opened inside the <b> element, it must be closed inside the <b> element.

XML Documents Must Have a Root Element

XML documents must contain one element that is the  parent  of all other elements. This element is called the  root  element.
<root>
  <child>
    <subchild>.....</subchild>
  </child>
</root>

XML Attribute Values Must be Quoted

XML elements can have attributes in name/value pairs just like in HTML.

In XML, the attribute values must always be quoted.

Study the two XML documents below. The first one is incorrect, the second is correct:

<note date=12/11/2007>
  <to>Tove</to>
  <from>Jani</from>
</note>

<note date="12/11/2007">
  <to>Tove</to>
  <from>Jani</from>
</note>

Entity References

Some characters have a special meaning in XML.

If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element.

This will generate an XML error:

<message>if salary < 1000 then</message>

To avoid this error, replace the "<" character with an  entity reference :
<message>if salary < 1000 then</message>

There are 5 predefined entity references in XML:
&lt; < less than
&gt; > greater than
&amp; & ampersand 
&apos; ' apostrophe
&quot; " quotation mark

Comments in XML

The syntax for writing comments in XML is similar to that of HTML.

<!-- This is a comment -->

White-space is Preserved in XML

HTML truncates multiple white-space characters to one single white-space:
HTML: Hello           Tove
Output: Hello Tove
With XML, the white-space in a document is not truncated.

XML Stores New Line as LF

In Windows applications, a new line is normally stored as a pair of characters: carriage return (CR) and line feed (LF). In Unix applications, a new line is normally stored as an LF character. Macintosh applications also use an LF to store a new line.

XML stores a new line as LF.


XML Elements

What is an XML Element?

An XML element is everything from (including) the element's start tag to (including) the element's end tag.

An element can contain:

  • other elements
  • text
  • attributes
  • or a mix of all of the above...

XML Naming Rules

XML elements must follow these naming rules:

  • Names can contain letters, numbers, and other characters
  • Names cannot start with a number or punctuation character
  • Names cannot start with the letters xml (or XML, or Xml, etc)
  • Names cannot contain spaces

Any name can be used, no words are reserved.


Best Naming Practices

Make names descriptive. Names with an underscore separator are nice: <first_name>, <last_name>.

Names should be short and simple, like this: <book_title> not like this: <the_title_of_the_book>.

Avoid "-" characters. If you name something "first-name," some software may think you want to subtract name from first.

Avoid "." characters. If you name something "first.name," some software may think that "name" is a property of the object "first."

Avoid ":" characters. Colons are reserved to be used for something called namespaces (more later).

XML documents often have a corresponding database. A good practice is to use the naming rules of your database for the elements in the XML documents.

Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software vendor doesn't support them.

从交换机安全配置,看常见局域网攻击 前言 构建零信任网络,自然离不开网络准入(NAC),这就涉及到交换机的一些安全测试,于是有了此文《从交换机安全配置看常见局域网攻击》。 交换机安全配置 如本文标题所说从交换机安全配置看常见的局域网攻击,那么下面提到的各种攻击方式,自然是建立在交换机安全配置之上来说的。我们通过h3c官方提供的《H3C 交换机安全加固手册》和《安全配置指导》,从这两份手册可以看出交换机支持的安全配置非常多,基本已经覆盖了各种我们熟知局域网攻击。下面就挑几个典型的攻击方式进行演示。 arp欺骗 【一>所有资源获取&lt 阅读详情

相关推荐

Navcat最新版的激活和安装教程(全网最靠谱,最快捷的方式)

现在最新版本navcat已经出到了16.3了,并且新版navcat也支持连接redis和图标等更多样化的功能,但是比较头疼的一件事就是,只能试用14天。那么接下来小编教大家如何用最简单的方式使用最新版navcat16.

weixin_50737119的博客 2万+

xml 单行注释_如何在XML标签块或单行中注释?

xml 单行注释XML comments are very useful in order to explain the XML tags. Also if we want to test some XML code with and without we can use commentsto enable or disable a single line or XML tag block. X...

cunjiu9486的博客 1560

新手友好的PythonUI库PySimpleGUI项目已下架,切换4.50.6版本的方法

过期后,如果还想使用 PySimpleGUI,则需要切换到版本 4,而版本 4 在 GitHub 上有很多社区维护的版本可以选择。开发团队尝试了 7 年,但始终没能获得足够的收入来维持项目的运营,尤其是开源项目通常面临资金不足的问题。商业许可证是永久有效的,用户可以在支持期结束后依然使用应用程序,并会提供离线版本的文档以供参考。尽管项目关闭,但对购买了商业许可证的用户,团队仍会在接下来的一年内提供支持。

baidu_34681715的博客 6858

XML 语法规则

 The syntax rules of XML are very simple and very strict. The rules are very easy to learn, and very easy to use.XML的语法规则是非常简单而又非常严格的;它非常易于学习,也非常易于使用。Because of this, creating software that can

qsd007的专栏 1677

STM32实战篇:使用USART发送/接收数据

在发送字符时也可以直接使用其对应的ASCLL码,例如: USART_SendData(USART1, 0x61);

qq_74114817的博客 596

Android Framework AMS面试题及参考答案

比如,应用 B 的 Activity 如果是 “singleTask” 启动模式,AMS 会查找应用 B 是否有包含该 Activity 的任务栈,若有则将这个任务栈切换到前台,并且清除该 Activity 之上的其他 Activity,实现流畅的跨应用跳转体验。如果一个 Activity 的启动依赖于另一个 Activity 的结果,AMS 会暂停当前 Activity 的部分生命周期操作,等待依赖的 Activity 完成相关操作后,再继续当前 Activity 的生命周期进程。

大模型大数据攻城狮的专栏 1857

关于xml配置文件无元素提示和the root element of the document is not <xsd:schema>.错误

这两个问题可以用同一种方式去解决。框架的XML文件在加载xsd或dtd文件时总是先试图在本地查找xsd文件,如果没有找到,才会转向去URL指定的路径下载。 解决方案如下: 按照图上标注的顺序依次点击。 当你点击第6步时,会弹出一个选择文件的窗口。你需要找到你本地对应的.xsd文件或.dtd文件。 并把xml文件中的schemal空间地址给填入到第7步的K

1万+

Mastercam软件二次开发:使用C#进行Mastercam二次开发

C#(发音为“C Sharp”)是一种现代、面向对象的编程语言,由微软开发,首次发布于2000年。它结合了C和C++的强大功能,同时引入了Java的垃圾回收机制,使得C#在开发效率和运行性能之间找到了一个良好的平衡点。C#的设计目标是提高开发者的生产力,它支持多种编程范式,包括面向对象、泛型、委托和事件等,这使得它成为开发Windows应用程序、Web应用程序、游戏(尤其是使用Unity引擎)和企业级应用的理想选择。

kkchenjj的博客 2214

XML的基础知识

XML的基础知识一、什么是XML?二、XML的树结构1.XML文档的基本结构2.XML文档实例3.书店的XML表示示例三、XML的语法1.XML的语法规则2.XML的实体引用 一、什么是XML? XML 指可扩展标记语言(EXtensible Markup Language); XML 是一种标记语言,很类似 HTML; XML 的设计宗旨是传输数据,而非显示数据; XML 标签没有被预定义,需...

weixin_43951995的博客 943

气象水文资料预处理:缺测数据插补延长等

简介气象水文资料预处理

WW、forever的博客 3769

虚拟网络的“隐形盾”:C#如何用代码把DDoS踢出门?

本文分享了如何用C#防御DDoS攻击的实战经验。通过三种核心防御策略:1)基于IP的速率限制中间件,使用滑动时间窗口算法控制请求流量;2)自动IP封禁服务,通过特征检测识别恶意IP并加入黑名单;3)优化数据库连接池和HTTP客户端连接池,合理配置资源参数。文中提供了详细的C#代码实现,包括限流中间件、IP封禁服务和连接池优化方案,并分享了生产环境中的调优经验,如配合Redis实现分布式限流、使用fail2ban自动封禁等技巧,帮助开发者构建更健壮的防御体系。

墨夶的博客 329

XML文档基础知识

工作中会经常与XML文件,以下的XML文档基础知识是否还记得? 本 Chat 你将会获得以下知识: 1、XML概述 2、XML语法 3、XML约束之DTD约束 4、JAXP进行DOM解析 适合人群:想了解XML文档...

GitChat 998

GameFramework框架详解之 DataTable配置表模块

一.前言: DataTable模块是项目的配置表模块,配置表一般是从excel导出csv/json/xml格式的,之所以是excel作为源文件,原因是因为策划同学使用配表最方便。然后一键导出到项目中,除了csv/json/xml配置文件外,一般还会伴随着导出配置的实体类,这样研发同学就可以使用了。GameFramework的DataTable模块也是秉持着这种一贯的策略来实现的。 二.DataRow DataRow在excel数据表中,对应的是一行数据,而在代码中对应的其实就是一条数据对象。 接口IData

TxNet 4725

——xml基础知识

XML数据格式 一、XML简单介绍 XML(extensible Markup language)是HTML的扩展标签语言,XML比HTML更加灵活,HTML的标签是固有的(已经被定义),而XML标签没有固定的,所有标签均可根据实际需要自行定义,但在语法要求上XML比HTML严格。在XML严格要求所有标签必须有开始标签和结束标签。 xml的宗旨,是做数据的传递,而不是数据展示。 二、XML文件格式...

weixin_43596601的博客 389

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

xml基础知识

1. XML 1. 概念 2. 语法 3. 解析 XML: 1. 概念:Extensible Markup Language 可扩展标记语言 * 可扩展:标签都是自定义的。 <user> <student> * 功能 * 存储数据 1. 配置文件 2. 在网络中传输 3. 作为数据库存储数据(理解) * xml与html的区别 1...

张三与王二麻子 5700

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

XML基础知识与DOM4J解析XML文件

首先导入DOM4J.jar包 public class xml { public static void main(String[] args) throws Exception { //创建SAXReader对象,用于读取xml文件 SAXReader reader=new SAXReader(); //读取xml文件,得到Docume...

Hsiao99的博客 257

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Java——XML基础知识

XML大小写敏感,不可省略结束标签,可以标签自闭合<img />,属性值必须用引号括起来。CDATA部分用<![CDATA[ ]]>来限定界限,它们是字符数据的一种特殊形式。可以用来包含含有<、>、&之类的字符串。CDATA部分不能包含字符串]]>。 读取一个XML文档,首先需要一个DocumentBuilder对象,该对象可以从Document...

weixin_30832351的博客 108

基础知识之XML

一、什么是XML 全称:Extensible Markup Language 中文名:可扩展标记语言 用于标记电子文件使其具有结构性的标记语言,可以用来标记数据,定义数据类型,允许用户对自己的标记语言进行定义的源语言。 XML主要用途是什么? XML用于传输数据与存储数据。 二、XML和HTML的区别 1)html标签不能自定义,从标签上不能达到“见词知意”的目的 表格

飞过海的博客 315

学习Spring必学的Java基础知识(4)----XML基础知识

学习Spring必学的Java基础知识(4)----XML基础知识 博客分类: 08_Java基础10_Spring 3.x企业应用开发实战04_SSH spring  引述要学习Spring框架的技术内幕,必须事先掌握一些基本的Java知识,正所谓“登高必自卑,涉远必自迩”。以下几项Java知识和Spring框架息息相关,不可不学(我将通过一个系列分别介绍这些Java基础知识

p0p0p0p01的专栏 172

关于XML基础知识

1.XML基础知识1.   一个xml文档可以分成两个基本部分:首部( header )内容( content ) 2.   xml名字空间规范中指定:xml文档中的每一个元素都处在一个名字空间中;如果没有指定的名字空间,缺省的名字空间就是和该元素相关联的名字空间。 3.   A document that is well-formed obeys all o

NO1陈刚-刚子扯谈 618

XML学习进阶(一、XML的基础知识)

我的博客开张了,第一次写Blog真不知道该写些什么,正好最近在整理之前的学习笔记,相信这对于那些初学者来说应该很有用,因此今天抽空整理的下,把它“贴”出来,希望对于那些刚接触编程的初学者能有用。这次我主要整理的XML的一些基本东西,与XML相关的其它内容将在稍后陆续发布。同时也谢谢您的光临!谢谢! 一、 XML的一些介绍 XML(Extensible Markup...

weixin_34055787的博客 1361
上一篇: python: import模块的相关问题
下一篇: ElementTree处理xml
wangst4321
博客等级 码龄16年 4粉丝 25原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值