1. XML: extensible markup language version="1.0"
- ##Extensible: all tags are customized
- Function: Data storage
- Configuration file
- Data transmission
- Differences between html and xml
- html is used for page display, xml is used for data Storage
- All tags in Html are predefined, and all tags in xml are customized
- ##HTML syntax is loose, xml syntax is strict
- Document declaration
- encoding specified document The default value of the code table is iso-8859-1
- standalone. Specify whether the document is independent yes or no
- must be written in the xml document. One line of
- is written as:
- Attributes
- Numbers cannot begin
- There must be and can only be one root element in the document
- The element needs to be closed correctly
- element names must comply with
- ##
- Escape characters>
- The data inside CDATA will be displayed as it is
- Attributes
- Attribute values must be enclosed in quotation marks. Both single and double quotation marks are OK
- Comments
- #
- Processing instructions: Basically no need now
- 3. XML constraints
- version version number fixed value 1.0
- Element names are case-sensitive
elements need to be nested correctly
Constraints are the writing rules of xml
-
Classification of constraints:
- Import xsd constraint document
Write root tag
-
Introducing the instance namespace xmlns:xsi="www.w3.org/2001/XMLSchema-instance"
- ##Introducing the namespace xsi:schemaLocation="www.itcast.cn/ xml student.xsd"
- Introducing the default namespace
- student.xsd
- student .xml
<?xml version="1.0"?> <xsd:schema xmlns="www.itheima.cn/xml" xmlns:xsd="www.w3.org/2001/XMLSchema" targetNamespace="www.itheima.cn/xml" elementFormDefault="qualified"> <xsd:element name="students" type="studentsType"/> <xsd:complexType name="studentsType"> <xsd:sequence> <xsd:element name="student" type="studentType" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="studentType"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="age" type="ageType" /> <xsd:element name="sex" type="sexType" /> </xsd:sequence> <xsd:attribute name="number" type="numberType" use="required"/> </xsd:complexType> <xsd:simpleType name="sexType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="male"/> <xsd:enumeration value="female"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="ageType"> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="0"/> <xsd:maxInclusive value="256"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="numberType"> <xsd:restriction base="xsd:string"> <xsd:pattern value="itheima_\d{4}"/> </xsd:restriction> </xsd:simpleType> </xsd:schema> <?xml version="1.0" encoding="UTF-8" ?>
<students xmlns="www.itheima.cn/xml" xsi:schemaLocation="www.itheima.cn/xml student.xsd" xmlns:xsi="www.w3.org/2001/XMLSchema-instance" > <student number="itheima_1001"> <name>asfd</name> <age>12</age> <sex>male</sex> </student> </students> <students xmlns:itheima="www.itheima.cn/xml" xsi:schemaLocation="www.itheima.cn/xml student.xsd" xmlns:xsi="www.w3.org/2001/XMLSchema-instance" > <itheima:student number="itheima_1001"> <itheima:name>asfd</itheima:name> <itheima:age>12</itheima:age> <theima:sex>male</itheima:sex> </itheima:student> </itheima:students>
<!ELEMENT students (student*) > <!ELEMENT student (name,age,sex)> <!ELEMENT name (#PCDATA)> <!ELEMENT age (#PCDATA)> <!ELEMENT sex (#PCDATA)> <!ATTLIST student number ID #REQUIRED> 唯一的,必须的 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE students SYSTEM "student.dtd"> <students> <student number="s0001" > <name>zs</name> <age>abc</age> <sex>yao</sex> </student> </students>
- If xml is used as a configuration file: read
- XML parsing ideas:
- Advantages: Does not occupy memory, fast
- Advantages: Because a dom tree will be formed in the memory, the dom tree can be added, deleted, modified, and checked
- Disadvantages: The DOM tree takes up a lot of memory and the parsing speed is slow
- Document Element Text Attribute Comment
- DOM: Load the document to memory, forming a DOM tree (document object), encapsulating various components of the document into some objects
- SAX: read line by line, event-driven
- Commonly used parsers for xml
- define a rule
- Usage steps
- XPath:
-
public classTestXPath2 { @Test publicvoidtest()throwsException{ SAXReaderread= new SAXReader(); Documentdocument= read.read("src/Dom4jTest.xml"); Listnodes= document.selectNodes("/bookstore//book/title"); for(inti= 0;i< nodes.size();i++) { Nodenode= (Node)nodes.get(i); System.out.println(node.getText()); } } }
selectSingleNode()
- selectNodes()
- Note: To import the package jaxen...jar
创建解析器 SAXReader reader = new SAXReader()
解析xml 获得document对象 Document document = reader.read(url)
// nodename 选取此节点。
// / 从根节点选取。
// // 从匹配选择的当前节点选择文档中的节点,而不考虑它们的位置。
// .. 选取当前节点的父节点。
// @ 选取属性。
// [@属性名] 属性过滤
// [标签名] 子元素过滤
-
@Test
//遍历所有元素节点
publicvoidtest2()throwsException{ //创建一个xml解析对象 SAXReaderreader= new SAXReader(); //把xml文档加载到document对象中 Documentdocument= reader.read("src/Book.xml"); Elementroot= document.getRootElement(); treeWalk(root); } privatevoidtreeWalk(Elementele){ //输出当前节点的名字 System.out.println(ele.getName()); //ele.nodeCount()得到当前节点的所有子节点的数量 for(inti= 0;i<ele.nodeCount();i++){ //取出下标为i的节点 Nodenode= ele.node(i); //判断当前节点是否为标签 if(nodeinstanceofElement){ //把node强转为标签(Element) treeWalk((Element)node); } } } }
public classTestDom4j { @Test publicvoidtest1()throwsException{ //创建一个xml解析对象 SAXReaderreader= new SAXReader(); //把xml文档加载到document对象中 Documentdocument= reader.read("src/Book.xml"); Elementroot= document.getRootElement(); // Element bookNode = root.element("书"); // System.out.println(bookNode.getName()); //得到当前节点所有的子节点 Listlist= root.elements(); //得到第二本书对象 ElementsecondBook= (Element)list.get(1); //得到当前节点的文本内容 Stringname= secondBook.element("书名").getText(); System.out.println(name); }
导入jar包 dom4j.jar
创建解析器
解析xml 获得document对象
SAXReader reader = new SAXReader()
Document document = reader.read(url)
JAXP sun公司提供的解析 支持dom和sax
JDOM
DOM4J dom for java民间方式,但是是事实方式,非常好,支持dom
解析xml
XPATH 专门用于查询
- If xml is used as a transfer file: write, read
- Disadvantages: Can only read, cannot write back
- Usage method
The above is the detailed content of Take you to a deeper understanding of XML. For more information, please follow other related articles on the PHP Chinese website!

Advanced features of RSS include content namespaces, extension modules, and conditional subscriptions. 1) Content namespace extends RSS functionality, 2) Extended modules such as DublinCore or iTunes to add metadata, 3) Conditional subscription filters entries based on specific conditions. These functions are implemented by adding XML elements and attributes to improve information acquisition efficiency.

RSSfeedsuseXMLtostructurecontentupdates.1)XMLprovidesahierarchicalstructurefordata.2)Theelementdefinesthefeed'sidentityandcontainselements.3)elementsrepresentindividualcontentpieces.4)RSSisextensible,allowingcustomelements.5)Bestpracticesincludeusing

RSS and XML are tools for web content management. RSS is used to publish and subscribe to content, and XML is used to store and transfer data. They work with content publishing, subscriptions, and update push. Examples of usage include RSS publishing blog posts and XML storing book information.

RSS documents are XML-based structured files used to publish and subscribe to frequently updated content. Its main functions include: 1) automated content updates, 2) content aggregation, and 3) improving browsing efficiency. Through RSSfeed, users can subscribe and get the latest information from different sources in a timely manner.

The XML structure of RSS includes: 1. XML declaration and RSS version, 2. Channel (Channel), 3. Item. These parts form the basis of RSS files, allowing users to obtain and process content information by parsing XML data.

RSSfeedsuseXMLtosyndicatecontent;parsingtheminvolvesloadingXML,navigatingitsstructure,andextractingdata.Applicationsincludebuildingnewsaggregatorsandtrackingpodcastepisodes.

RSS documents work by publishing content updates through XML files, and users subscribe and receive notifications through RSS readers. 1. Content publisher creates and updates RSS documents. 2. The RSS reader regularly accesses and parses XML files. 3. Users browse and read updated content. Example of usage: Subscribe to TechCrunch's RSS feed, just copy the link to the RSS reader.

The steps to build an RSSfeed using XML are as follows: 1. Create the root element and set the version; 2. Add the channel element and its basic information; 3. Add the entry element, including the title, link and description; 4. Convert the XML structure to a string and output it. With these steps, you can create a valid RSSfeed from scratch and enhance its functionality by adding additional elements such as release date and author information.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment