1 有且只有乙個根元素
2 xml標籤大小寫正確區分
3 正確使用結束標籤
4 正確巢狀標籤
5 使用了合法的標籤名
6 定義有效的屬性
element-name:元素名稱
//空元素
//文字元素
//混合元素,標籤裡包含了其他的元素
, :順序
| :或
次數: +(1~n) *(0~n) ?(0或1) 沒有(1)
att_name:屬性名
att_name type
> id
:唯一
(男|女)
:列表 「
值」:預設值
cdata
:文字
idref
:外來鍵
#required
:不為空
#implied :允許為空
&(邏輯與)&
>
(大於)
<
<
(小於)
> 「
(雙引號)"
『(單引號)'
config
.xml檔案
<?xml version="1.0" encoding="utf-8"?>
doctype
config[
config (action
*)>
action (forward
*)>
forward
empty
>
action
path cdata
#required
type cdata
#required
>
forward
name cdata
#required
path cdata
#required
redirect (true|false) "false"
>
]>
<config
>
<action
path
="/regaction"
type
="test.regaction"
>
<forward
name
="failed"
path
="/reg.jsp"
redirect
="false"
/>
<forward
name
="success"
path
="/login.jsp"
redirect
="true"
/>
action
>
<action
path
="/loginaction"
type
="test.loginaction"
>
<forward
name
="failed"
path
="/login.jsp"
redirect
="false"
/>
<forward
name
="success"
path
="/main.jsp"
redirect
="true"
/>
action
>
config
>
*.properties
*.xml
xmlwebservice
json
xml和*.properties(屬性檔案)
***.class.getresourceasstream("/config.properties");
***.class.getresourceasstream("config2.properties");
//輸入流 類名.class.getresourceasstream 填寫配置檔案的位址 //
/db.properties為
src目錄下
inputstream is = test.class.getresourceasstream("/db.properties");
//解析
properties properties = new properties();
properties.load(is);
//鍵值對的儲存方式,根據鍵的名稱獲得值
string
uname
= properties.getproperty("
uname
");
string user = properties.getproperty("user");
string password = properties.getproperty("password");
system.out.println(
uname
+" "+user+" "+password);
inputstream is = test.class.getresourceasstream("/students.xml");
saxreader saxreader = new saxreader();
document read = saxreader.read(is);
string
xpath
="/students/student";
//得到
xml檔案裡students下所有student元素節點
list
li= read.selectnodes(
xpath);
for (node node :
li)
//得到某個元素節點
inputstreamis
=test
.class
.getresourceasstream("/students.xml");
saxreadersaxreader
=new
saxreader();
documentread
= saxreader.read(is);
//得到student元素節點下乙個
sid為s003的name元素節點
stringxpath
="/students/student[@sid='s003']/name";
elementnameelement
= (element)read.selectsinglenode(xpath);
system
.out
.println(nameelement.gettext());
android中解析XML檔案
上面這個鏈結詳細介紹了幾種xml的解析方法以及原理。下面是實現思路 1.讀取xml檔案 2.獲取讀取事件,如果檔案結束,則停止解析 3.處理讀取事件 4.回到第二步。下面是實現過程 1.要解析的xml檔案內容 name jim age 123 gender male email mail hostn...
iOS中XML文件解析
1 讀取檔案路徑 nsstring path nsbundle mainbundle pathforresource student oftype txt 2 讀取資料 nsdata data nsdata datawithcontentoffile path 1 開始xml sax解析,需要遵循n...
iOS中xml檔案解析
xml檔案內容 id 1 jackname 2015personid 20age person id 2 rosename 2016personid 18age person id 3 tomname 2017personid 19age person id 4 jerryname 2018pers...