Xml的一些基本概念
Document element (also can be called as root element) is needed for a valid xml document.
Xml namespace is done by defining the Universal Resource Indicator (URIs) which includes Uniform Resource Locators (URL) and Uniform Resource Numbers (URN).
There are 2 ways to define a namespace:
1). Default namespace: define it using the xmlns attribute without a prefix. For example: <html xmlns="http://www.w3.org/1999/xhtml">
2). Prefixed namespace: define it using the xmlns attribute with a prefix. For example: <blist:books xmlns:blist="http://www.wrox.com/books/xml">
DTD may either be stored internally as part of the XML document or externally in a separate file, accessible via a URL.
an internal example:
<?xml version=”1.0” ?>
<!-- DTD is not parsed as XML, but read by parser for validation -->
<!DOCTYPE book [
<!ELEMENT book (title, chapter+)>
<!ATTLIST book author CDATA #REQUIRED>
<!ELEMENT title (#PCDATA)>
<!ELEMENT chapter (#PCDATA)>
<!ATTLIST chapter id #REQUIRED>
]>
Extensible Stylesheet Language Transformation (XSLT) is a language used for converting XML documents from one format to another. The two below are used mainly:
1) Converting XML into HTML
2) Converting XML into another XML
Document Object Model (DOM): this API will laod the whole xml document into the RAM to do the parsing work. It is well suited for traversing and modifying an XML document, but provides little support for finding an arbitrary element or attribute. Of course it has the lower performance.
Simple API for XML (SAX): it loads the document as a stream of data parts instead of aggregation. It's straight-forward only.
Difference between SAX and DOM:
1) DOM uses a parallel approach to the document, it can access several different level nodes with one method. SAX only can starting at the beginning and responding to its contents once for each node and in the order they appear in the document.
2) DOM needs larger memory and has a lower performance. SAX needs smaller memory and has a higher performance. So if reading a very big xml document, using SAX is better.
As DOM doesn't support well for finding an arbitrary element or attribute, XPath can help us to do the work. It is a navigational query language for locating data within an XML document.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】