XML知识1--xml格式熟悉
来源:互联网 发布:easymule 软件 编辑:程序博客网 时间:2024/05/01 20:03
一.基本认识
这是一个很简单的XML文档,场景是一个网上书店,有很多书,每本书有两个属性,一个是书名[title],一个为是否展示[show],最后还有一项是这些书的拥有者[owner]信息。
- <?xml version="1.0" encoding="UTF-8"?>
- <books>
- <book show="yes">
- <title>Dom4j Tutorials</title>
- </book>
- <book show="yes">
- <title>Lucene Studing</title>
- </book>
- <book show="no">
- <title>Lucene in Action</title>
- </book>
- <owner>O'Reilly</owner>
- </books>
1.整个文档在程序里面称为“Document”
2.books,book,title,owner 都是 “Element”---元素 。books可以称为根元素。元素下面可以嵌套元 素,比如book元素下面就包含了title元素。
3.<book show="yes"> ,元素括起来的show是“Attribute”---属性
4.我们可以将Element的基本类似成树的层次来理解。
二.带校验的xml文档
xml必须遵守一定的格式约束,如果上面的xml片段写成下面这个格式,虽然不存在语法错误,意义就完全不同了(owner会变成某本书的出版社,而不是所有书的拥有者)
- <?xml version="1.0" encoding="UTF-8"?>
- <books>
- <book show="yes">
- <title>Dom4j Tutorials</title>
- </book>
- <book show="yes">
- <title>Lucene Studing</title>
- </book>
- <book show="no">
- <title>Lucene in Action</title>
- <owner>O'Reilly</owner>
- </book>
- </books>
因此看看我们使用的spring的配置xml吧:
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
- default-autowire="byName" default-lazy-init="true">
- <!-- 可以提供一些全局变量的配置:) -->
- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="location"
- value="classpath:globalVariables.properties" />
- </bean>
- </beans>
在根元素<beans>中申明了长长的一串.xsd文件,实际是基于Schema的xml验证文档,来约束配置的正确性。
下面看struts2的配置:
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
- "http://struts.apache.org/dtds/struts-2.0.dtd">
- <struts>
- </struts>
这是xml标准格式,通过<!DOCTYPE>元素来指定该xml的验证格式。struts2的验证文档为基于dtd的 strts-2.0.dtd。
- XML知识1--xml格式熟悉
- XML知识小结1
- XML学习(2)------由浅入深熟悉XML
- Xml知识
- xml知识
- xml知识
- XML知识
- xml格式
- XML 格式
- XML格式
- xml 格式
- xml格式
- XML格式
- xml格式
- XML学习---认识XML及熟悉XML代码写法
- 【XML系列】-----XML文档格式
- Mybatis XML 映射配置文件 -- 熟悉配置
- Xml与知识管理
- load balanced cluster
- 入门着怎样建一个普通的触发器
- 温(湿)度测量系统主机简介
- ids for this class must be manually assigned before calling save():***错误说明
- 闲谈 选择自 fengzi_zhu 的 Blog
- XML知识1--xml格式熟悉
- 段错误bug的调试
- java中的类和方法的修饰符(转)
- 自定义TabControl全部代码
- 谈PHP生成静态页面
- T_Monitor温湿度监控软件简介
- windows安装基于Apache的SVN服务器(包括SSL配置)
- flex 实现鼠标画线
- 发布了一个资源