Solaris10與EMCCX3-10c實現(xiàn)FC-SAN實施手冊_第1頁
Solaris10與EMCCX3-10c實現(xiàn)FC-SAN實施手冊_第2頁
Solaris10與EMCCX3-10c實現(xiàn)FC-SAN實施手冊_第3頁
Solaris10與EMCCX3-10c實現(xiàn)FC-SAN實施手冊_第4頁
Solaris10與EMCCX3-10c實現(xiàn)FC-SAN實施手冊_第5頁
已閱讀5頁,還剩47頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、 Solaris 10與EMC CX3-10c實現(xiàn)FC-SAN實施手冊現(xiàn)場背景:服務(wù)器3臺,2臺Sun Fire V490,1臺Sun Fire V250。存儲為DELL|EMC CX3-10c,配備8TB硬盤,一臺Brocade SW200E光纖交換機(jī)。目的:實現(xiàn)FC-SAN構(gòu)架。拓?fù)鋱D:實施步驟:先完成Dell|EMC CX3-10c初始化,配置兩個管理IP,分別為:XX.XX.XX.XX。建立服務(wù)器、光纖交換機(jī)、存儲之間的鏈路。初始化光纖交換機(jī),配置管理地址:XX.XX.XX.XX在Navisphere Manager管理界面發(fā)現(xiàn)鏈路。在服務(wù)器端安裝Navisphere agent注冊,

2、安裝PowerPath多鏈路管理軟件。具體安裝操作如下:Navisphere agent的安裝與配置先將光盤mount上后,再執(zhí)行下面的命令:pkgadd -d NAVIAGNT.pkg會出現(xiàn)下述提示信息,按照提示信息選擇安裝即可。Select the packages that you want to install by doing one of thefollowing:? Enter 1 (to install the host agent)or? Enter 2 (to install CLI) or Enter All (to install both the host agent

3、and CLI)Enter y and y to begin the installation.The installation program looks for any agent configuration filesyou may already have on your system. If the program doesnot find any agent configuration files, then you have finishedinstalling the agent; go to step 10q. If the program does find anyexis

4、ting configuration files, it displays a message like the following:At Least 1 saved config file exists for NavisphereAgent.Please select 1 of the following:1Restore/etc/Navisphere/.Naviagent-config.000120:10592Restore/etc/Navisphere/.Naviagent-config.000121:14083 QuitSelect number 1 - 3.修改agent.conf

5、ig配置文件,主要方法如下:修改/etc/Navisphere/agent.configVi /etc/Navisphere/agent.config 修改內(nèi)容為:# Navisphere agent.config# # This file is used by Navisphere Agent to configure# site specific values.# All entries in this file have this form:# object value-list# Where object tells what sort of information is to# be

6、 configured, and value-list is a# whitespace-separated list of values to be configured.# Samples, which should be edited, appear below for all# permissible types of objects.# White space (tabs, space, line-feeds,# carriage-returns) and blank lines are ignored;# To continue a line onto the next line,

7、 use as the# last character of that line. The is dropped when# the next line is concatenated to the continued line.# Description specification# # The clarDescr object takes arbitrary text values# intended to describe the agent and its location.#clarDescr Navisphere Agent# The clarContact object take

8、s arbitrary text values# intended to describe who is responsible for the# configured agent, and how to reach them.#clarContact John Smith, 800-555-1212# Device specification.# # The format of device objects for CLARiiON devices# is:# devicedevice-specname description# where the device-specification

9、is the device name to# open to access the CLARiiON device. It can be a# SCSI-2 file name. If this is auto, all attached# arrays with bound LUNs will be automatically# configured. (Currently, dummy arguments are required# for name and description, when using# auto-configuration.) This can NOT be defa

10、ulted.# The name is the per CLARiiON name that can be used to# identify each CLARiiON to the manager application.# The name is REQUIRED and cannot contain spaces (even# if surrounded by quotes). This can NOT be defaulted.# The description is a quoted string that contains a# brief description of the

11、CLARiiON chassis being# managed. It defaults to if not specified, and to# the device name for auto-configuration.# SAMPLES:# device c0t0d0 NAVISPHERE-1 NAVISPHERE-1# automatically detect manageable devicesdevice auto auto# User Specification.# # The format of user objects is# user localUserId# OR# u

12、ser userIdhostname在此處添加存儲系統(tǒng)SPA和SPB管理地址即可user HYPERLINK mailto:systemXX.XX.XX.XX systemXX.XX.XX.XX user systemXX.XX.XX.XX# These build a list of users who are allowed to perform# WRITE operations to the CLARiiON devices managed by# this agent. By default, as specified below, only root# on this machin

13、e has WRITE access. Others can be# granted access by including their login name and host# which they can access from. A null list prevents# anyone, including admin, from having write access. In# order to get write access, this file would have to be# modified and the Agent stopped and restarted to# r

14、e-read the configuration file, or an appropriate# remote configuration file would have to be sent to the# agent from an already-priviledged user.user root # only on this machine#user sbluepicasso # individual user sblue on# host picasso#user lgreenhannibal # individual user lgreen on# host hannibal#

15、 Poll specification# # The poll object takes a numerical count of seconds.# This specifies how often the agent solicits# information from the array, rather than using cached# information. The minimum is 10.#poll 60# Eventlog specification# # The eventlog object takes a numerical count of log# entrie

16、s.# This defines the maximum number of SP log events# received by the agent on startup, and received by# clients per poll. A value of 0 causes the devices# entire log to be read at startup. A minimum of 100# events will be read on serial, and 2048 on fibre,# overriding any lower value configured bel

17、ow.#eventlog 100# Baud Rate specification# # If the agent is using a serial port to manage a# device, the next entry can specify either 9600 baud# or 19200 baud.#baud 9600# end of configuration file#保存配置文件,然后可以啟動/停止agent服務(wù)。命令如下:bash3.00#/etc/init.d/agent stopbash3.00#/etc/init.d/agent start如果安裝配置正常,

18、啟動agent服務(wù)后在Navisphere Manager管理界面中的Connective中會看到鏈路狀態(tài)register為yes。如register顯示為no,可以考慮重啟服務(wù)器或者重啟agent服務(wù),或者在Navisphere Manager界面中進(jìn)行手動注冊也可以。注冊完成后會在鏈路狀態(tài)中顯示主機(jī)名稱等信息。PowerPath的安裝與注冊PowerPath的安裝1、Mount CDROM2、bash3.00# mkdir /unload3、bash3.00#cd /unload4、bash3.00#cp /. 從光盤將安裝文件拷貝到新建的目錄下面。5、bash3.00# gunzip 解

19、壓縮文件6、bash3.00# tar -xvf 解壓縮文件7、bash3.00#pkgadd d . 安裝PowerPath按照下述提示操作:SPARC host:The following packages are available:EMCpower EMC PowerPath(sparc) 5.2.x_bxxxSelect package(s) you wish to process (or all toprocess all packages). (default: all) ?,?,q:x86 (i386) host:The following packages are avail

20、able:EMCpower EMC PowerPath(i386) 5.2.x_bxxxSelect package(s) you wish to process (or all toprocess all packages). (default: all) ?,?,q:Enter 1 and press ENTER. Enter package base directory (default: /opt):Press ENTER to accept the default base directory (/opt), or type thepath to an alternate base

21、directory and press ENTER.This package contains scripts which will be executedwith super-user permission during the process ofinstalling this package.Do you want to continue with the installation of y,n,?Enter y and press ENTER.Installation of was successful.8、安裝完成后需要進(jìn)行PowerPath的注冊注冊方法如下:bash3.00#/e

22、tc/emcpreg -installYou see the following output:= EMC PowerPath Registration =Do you have a new registration key or keys to enter? nType y and press ENTER.You see the following output:Enter the registration key(s) for your product(s),one per line, pressing Enter after each key.After typing all keys,

23、 press Enter again.Key (Enter if done):Enter the PowerPath registration key and press ENTER. You can alsoadd keys for other technologies, such as PowerPath MigrationEnabler or PowerPath Encryption with RSA.If you entered a valid key, you see the following output:1 key(s) successfully added.Key succe

24、ssfully installed.Key (Enter if done):Press ENTER. You see the following output if you entered one key:1 key(s) successfully registered.在PowerPath軟件安裝注冊完成后重啟服務(wù)器,輸入下述命令可以看到服務(wù)器與存在之間的兩條鏈路:bash3.00#powermt display dev=all會顯示鏈路情況。還需要將Solaris主機(jī)的MPxIO功能關(guān)閉。(主要是由于Solaris自帶的MPxIO功能與PowerPath的多路徑功能相沖突)具體修改文件如下

25、:修改/kernel/drv/fp.conf,修改內(nèi)容如下:mpxio-disable=yes修改/kernel/drv/scsi_vhci.conf,修改內(nèi)容如下:mpxio-disable=yes修改完成后,運(yùn)行如下命令:powermt display dev=all powermt check (Choose A for all. Clear the dead paths.) devfsadm C (Scan the SCSI bus.) powercf -q (Rebuild the logical link layer.) powermt config (Bring the devi

26、ce pathsinto PowerPath control.) powermt save (Save the current configuration.)完成配置保存等工作后PowerPath軟件即可正常使用。存儲建立RAID Group,Storage Group,將服務(wù)器與LUN映射關(guān)系對應(yīng)上。服務(wù)器端識別存儲,格式化硬盤以及做文件系統(tǒng)。具體操作如下:sh-3.00# formatSearching for disks.doneAVAILABLE DISK SELECTIONS: 0. c0t0d0 /pci1d,700000/scsi4/sd0,0 1. c0t8d0 /pci1d,

27、700000/scsi4/sd8,0 2. c3t0d0 /pci1d,700000/QLGC,qlc2/sd0,0 3. c3t1d0 /pci1d,700000/QLGC,qlc2/sd1,0 4. emcpower0a /pseudo/emcp0Specify disk (enter its number): 4selecting emcpower0adisk formattedFORMAT MENU: disk - select a disk type - select (define) a disk type partition - select (define) a partiti

28、on table current - describe the current disk format - format and analyze the disk repair - repair a defective sector label - write label to the disk analyze - surface analysis defect - defect list management backup - search for backup labels verify - read and display labels inquiry - show vendor, pr

29、oduct and revision volname - set 8-character volume name ! - execute , then return quitformat pPARTITION MENU: 0 - change 0 partition 1 - change 1 partition 2 - change 2 partition 3 - change 3 partition 4 - change 4 partition 5 - change 5 partition 6 - change 6 partition select - select a predefined

30、 table modify - modify a predefined partition table name - name the current table print - display the current table label - write partition map and label to the disk ! - execute , then return quitpartition pCurrent partition table (original):Total disk sectors available: 3076627422 + 16384 (reserved

31、 sectors)Part Tag Flag First Sector Size Last Sector0 root wm 34 128.00MB 262177 1 swap wu 262178 128.00MB 524321 2 unassigned wm 0 0 0 3 unassigned wm 0 0 0 4 unassigned wm 0 0 0 5 unassigned wm 0 0 0 6 usr wm 524322 1.43TB 3076627421 8 reserved wm 3076627422 8.00MB 3076643805 partition labelReady

32、to label disk, continue? ypartition qFORMAT MENU: disk - select a disk type - select (define) a disk type partition - select (define) a partition table current - describe the current disk format - format and analyze the disk repair - repair a defective sector label - write label to the disk analyze

33、- surface analysis defect - defect list management backup - search for backup labels verify - read and display labels inquiry - show vendor, product and revision volname - set 8-character volume name ! - execute , then return quitformat q創(chuàng)建文件系統(tǒng),Solaris默認(rèn)格式bash-3.00# newfs /dev/rdsk/emcpower0g newfs:

34、 建構(gòu)新的文件系統(tǒng) /dev/rdsk/ emcpower0g: (y/n)? y警告:最后一個未分配柱面中的 1104 扇區(qū)/dev/rdsk/ emcpower0g: 在 500668 磁道上,48 扇區(qū)的 128 柱面的 3076103088 扇區(qū)1502003.5MB 在 3502 柱面群組 (143 c/g, 429.00MB/g, 448 i/g)超塊 (fsck -F ufs -o b=#) 備份在:32, 878752, 1757472, 2636192, 3514912, 4393632, 5272352, 6151072, 7029792, 7908512,初始化柱面組:最

35、后 10 個柱面組的超級塊備份位置: 3068047904, 3068926624, 3069805344, 3070684064, 3071562784, 3072441504, 3073320224, 3074198944, 3075077664, 3075956384,文件系統(tǒng)做完。掛載硬盤bash-3.00# mkdir emcdiskbash-3.00# mount /dev/dsk/ emcpower0g /mnt/emcdisk/其它鏈路也如上述操作,完成后運(yùn)行下面命令可以看到磁盤大小以及利用情況。bash-3.00# df -kh文件系統(tǒng) 大小 用了 可用 容量 掛接在/dev

36、/dsk/c0t0d0s0 32G 1.1G 30G 4% /devices 0K 0K 0K 0% /devicesctfs 0K 0K 0K 0% /system/contractproc 0K 0K 0K 0% /procmnttab 0K 0K 0K 0% /etc/mnttabswap 2.1G 1.0M 2.1G 1% /etc/svc/volatileobjfs 0K 0K 0K 0% /system/object/dev/dsk/c0t0d0s3 23G 4.3G 19G 19% /usrfd 0K 0K 0K 0% /dev/fd/dev/dsk/c0t8d0s7 67G 7

37、43M 66G 2% /varswap 2.1G 312K 2.1G 1% /tmpswap 2.1G 24K 2.1G 1% /var/run/dev/dsk/c0t0d0s6 1.2G 83M 1.1G 7% /temp/dev/dsk/c0t0d0s7 10G 1.9G 8.2G 19% /export/home/dev/dsk/emcpower0g 1.4T 64M 1.4T 1% /mnt/emcdisk硬盤自動掛載,修改配置文件,配置文件在/etc/vfstab具體修改參考下面文檔:bash-3.00# vi /etc/vfstab#device device mount FS f

38、sck mount mount#to mount to fsck point type pass at boot options#fd - /dev/fd fd - no -/proc - /proc proc - no -/dev/dsk/c0t0d0s1 - - swap - no -/dev/dsk/c0t0d0s0 /dev/rdsk/c0t0d0s0 / ufs 1 no -/dev/dsk/c0t0d0s3 /dev/rdsk/c0t0d0s3 /usr ufs 1 no -/dev/dsk/c0t8d0s7 /dev/rdsk/c0t8d0s7 /var ufs 1 no -/d

39、ev/dsk/c0t0d0s7 /dev/rdsk/c0t0d0s7 /export/home ufs 2 yes -/dev/dsk/c0t0d0s6 /dev/rdsk/c0t0d0s6 /temp ufs 2 yes -/devices - /devices devfs - no -ctfs - /system/contract ctfs - no -objfs - /system/object objfs - no -swap - /tmp tmpfs - yes -/dev/dsk/emcpower0g /dev/rdsk/emcpower0g /mnt/emcdisk ufs 1

40、yes -光纖交換機(jī)配置zone光纖交換機(jī)主要配置管理ip地址,zone等,在初始化時已經(jīng)完成了ip地址的配置,配置zone的方法如下:SW200E:admin switchshow 查看交換機(jī)信息switchName: SW200EswitchType: 34.0switchState: Online switchMode: NativeswitchRole: PrincipalswitchDomain: 1switchId: fffc01switchWwn: 10:00:00:05:1e:5b:f7:3ezoning: ON (XXXX)switchBeacon: OFFArea Port

41、 Media Speed State Proto= 0 0 id N4 Online F-Port 21:00:00:1b:32:08:2a:d4 1 1 id N4 Online F-Port 50:06:01:69:41:e0:b2:5f 2 2 id N4 Online F-Port 50:06:01:61:41:e0:b2:5f 3 3 id N4 Online F-Port 21:00:00:e0:8b:8f:57:b3 4 4 id N4 Online F-Port 21:00:00:e0:8b:8f:a8:b3 5 5 id N4 No_Light 6 6 id N4 No_Li

42、ght 7 7 id N4 No_Light 8 8 - N4 No_Module (No POD License) Disabled 9 9 - N4 No_Module (No POD License) Disabled 10 10 - N4 No_Module (No POD License) Disabled 11 11 - N4 No_Module (No POD License) Disabled 12 12 - N4 No_Module (No POD License) Disabled 13 13 - N4 No_Module (No POD License) Disabled

43、 14 14 - N4 No_Module (No POD License) Disabled 15 15 - N4 No_Module (No POD License) DisabledSW200E:admin alicreate “SPA_0”,” 50:06:01:69:41:e0:b2:5f” /創(chuàng)建WWN的別名SW200E:admin alicreate “SPB_0”,” 50:06:01:61:41:e0:b2:5f”SW200E:admin alicreate “mailbak”,” 21:00:00:e0:8b:8f:57:b3”SW200E:admin alicreate

44、“student_mail”,” 21:00:00:1b:32:08:2a:d4”SW200E:admin alicreate “v490”,” 21:00:00:e0:8b:8f:a8:b3”SW200E:admin zonecreate “bak”,” SPA_0; SPB_0; mailbak” /創(chuàng)建zoneSW200E:admin zonecreate “mail”,” SPA_0; SPB_0; v490”SW200E:admin zonecreate “st_mail”,” SPA_0; SPB_0; student_mail”SW200E:admin cfgcreate XXX

45、X, bak; mail ;st_mail /創(chuàng)建cfgSW200E:admin cfgsave “XXXX” /保存cfgSW200E:admin cfgenable “XXXX” /enable cfg配置完成??梢酝ㄟ^switchshow、fabricshow、zoneshow、cfgshow等查看配置。一定要注意創(chuàng)建別名時WWN的準(zhǔn)確性。其它注意事項以及特殊情況處理:PowerPath鏈路不正常情況下的處理PowerPath鏈路不正常主要有幾種情況:鏈路識別不了解決辦法:重啟服務(wù)器?;蛘呤褂萌缦旅睿篵ash3.00#powermt checkbash3.00#powermt rest

46、ore掃描通道bash3.00#powercf q bash3.00#powermt configbash3.00#powermt save在Navisphere Manager上檢查鏈路發(fā)現(xiàn)情況,如發(fā)現(xiàn)不了,進(jìn)行掃描,檢查HBA卡狀態(tài),如果狀態(tài)不對,需要安裝HBA卡驅(qū)動。鏈路數(shù)量狀態(tài)不對當(dāng)鏈路數(shù)量狀態(tài)不對時可以使用A中所提到的命令進(jìn)行鏈路通道掃描,同時結(jié)合Navisphere Manager 檢查鏈路情況,可以運(yùn)行CTRL+ALT+SHIFT+F12進(jìn)入工程師配置模式,密碼是messner.檢查鏈路以及Storage Group主機(jī)配置信息是否勾選。同時也可以檢查光纖交換機(jī)配置信息。修改So

47、laris配置文件系統(tǒng)不能啟動的問題在修改vfstab等文件造成系統(tǒng)啟動不起來,需要采用單用戶模式將配置文件修改后再重啟即可。主要方法如下:1插入Solaris 10光盤2利用光盤啟動到單用戶模式ok boot cdrom -s3裝配/(root)文件系統(tǒng)到/a目錄,以允許對磁盤上的文件系統(tǒng)的訪問。# mount /dev/dsk/c0t0d0s0 /a4設(shè)置并且輸出TERM變量允許vi編輯器進(jìn)行工作# TERM=sun# export TERM5編輯/etc/vfstab文件并且糾正問題。然后退出保存文件# vi /a/etc/vfstab:wq!6卸載文件系統(tǒng)# cd /# umount

48、/a7重新啟動系統(tǒng)# reboot附錄資料:不需要的可以自行刪除 libxml2應(yīng)用實例Libxml2 是一個xml的c語言版的解析器,本來是為Gnome項目開發(fā)的工具,是一個基于MIT License的免費(fèi)開源軟件。它除了支持c語言版以外,還支持c+、PHP、Pascal、Ruby、Tcl等語言的綁定,能在Windows、Linux、Solaris、MacOsX等平臺上運(yùn)行。功能還是相當(dāng)強(qiáng)大的,相信滿足一般用戶需求沒有任何問題。二、 Libxml2安裝:一般如果在安裝系統(tǒng)的時候選中了所有開發(fā)庫和開發(fā)工具的話(Fedora Core系列下),應(yīng)該不用安裝,下面介紹一下手動安裝: 1) 從xml

49、soft站點或ftp()站點下載libxml壓縮包(libxml2-xxxx.tar.gz)2) 對壓縮包進(jìn)行解壓縮 tar xvzf libxml2-xxxx.tar.gz3) 進(jìn)入解壓縮后的文件夾中運(yùn)行 ./configure -prefix /home/user/myxml/xmlinst(此處為待安裝的路徑)或者直接使用 ./configure make make install 4) 添加路徑 export PATH=/home/user/myxml/xmlinst/bin:$PATH 說明:為了結(jié)構(gòu)清晰,最好將libxml2不安裝在解壓目錄中。安裝完成后就可以使用簡單的代碼解析XM

50、L文件,包括本地和遠(yuǎn)程的文件,但是在編碼上有一些問題。Libxml默認(rèn)只支持UTF8的編碼,無論輸入輸出都是UTF-8,所以如果你解析完一個XML得到的結(jié)果都是UTF8的,如果需要輸出GB2312或者其它編碼,需要ICONV來做轉(zhuǎn)碼(生成UTF8編碼的文件也可以用它做),如果系統(tǒng)中沒有安裝iconv的話,需要安裝libiconv。 1) 下載libiconv壓縮包(例如libiconv-1.11.tar.gz) 2) 對壓縮包進(jìn)行解壓縮tar xvzf libiconv-1.11.tar.gz 3) 進(jìn)入解壓縮后的文件夾中運(yùn)行 ./configure make make install三、關(guān)于

51、XML:在開始研究 Libxml2 庫之前,先了解一下XML的相關(guān)基礎(chǔ)。XML 是一種基于文本的格式,它可用來創(chuàng)建能夠通過各種語言和平臺訪問的結(jié)構(gòu)化數(shù)據(jù)。它包括一系列類似 HTML 的標(biāo)記,并以樹型結(jié)構(gòu)來對這些標(biāo)記進(jìn)行排列。例如,可參見清單 1 中介紹的簡單文檔。為了更清楚地顯示 XML 的一般概念,下面是一個簡化的XML文件。清單 1. 一個簡單的 XML 文件 root delete 10清單 1 中的第一行是 XML 聲明,它告訴負(fù)責(zé)處理 XML 的應(yīng)用程序,即解析器,將要處理的 XML 的版本。大部分的文件使用版本 1.0 編寫,但也有少量的版本 1.1 的文件。它還定義了所使用的編碼

52、。大部分文件使用 UTF-8,但是,XML 設(shè)計用來集成各種語言中的數(shù)據(jù),包括那些不使用英語字母的語言。接下來出現(xiàn)的是元素。一個元素以開始標(biāo)記 開始(如 ),并以結(jié)束標(biāo)記 結(jié)束(如 ),其中使用斜線 (/) 來區(qū)別于開始標(biāo)記。元素是 Node 的一種類型。XML 文檔對象模型 (DOM) 定義了幾種不同的 Nodes 類型,包括:Elements(如 files 或者 age)Attributes(如 units)Text(如 root 或者 10)元素可以具有子節(jié)點。例如,age 元素有一個子元素,即文本節(jié)點 10。XML 解析器可以利用這種父子結(jié)構(gòu)來遍歷文檔,甚至修改文檔的結(jié)構(gòu)或內(nèi)容。Li

53、bXML2 是這樣的解析器中的其中一種,并且文中的示例應(yīng)用程序正是使用這種結(jié)構(gòu)來實現(xiàn)該目的。對于各種不同的環(huán)境,有許多不同的解析器和庫。LibXML2 是用于 UNIX 環(huán)境的解析器和庫中最好的一種,并且經(jīng)過擴(kuò)展,它提供了對幾種腳本語言的支持,如 Perl 和 Python。四、Libxml2中的數(shù)據(jù)類型和函數(shù)一個函數(shù)庫中可能有幾百種數(shù)據(jù)類型以及幾千個函數(shù),但是記住大師的話,90%的功能都是由30%的內(nèi)容提供的。對于libxml2,我認(rèn)為搞懂以下的數(shù)據(jù)類型和函數(shù)就足夠了。1)內(nèi)部字符類型xmlCharxmlChar是Libxml2中的字符類型,庫中所有字符、字符串都是基于這個數(shù)據(jù)類型。事實上它

54、的定義是:xmlstring.htypedef unsigned char xmlChar;使用unsigned char作為內(nèi)部字符格式是考慮到它能很好適應(yīng)UTF-8編碼,而UTF-8編碼正是libxml2的內(nèi)部編碼,其它格式的編碼要轉(zhuǎn)換為這個編碼才能在libxml2中使用。還經(jīng)常可以看到使用xmlChar*作為字符串類型,很多函數(shù)會返回一個動態(tài)分配內(nèi)存的xmlChar*變量,使用這樣的函數(shù)時記得要手動刪除內(nèi)存。2) xmlChar相關(guān)函數(shù)如同標(biāo)準(zhǔn)c中的char類型一樣,xmlChar也有動態(tài)內(nèi)存分配、字符串操作等相關(guān)函數(shù)。例如xmlMalloc是動態(tài)分配內(nèi)存的函數(shù);xmlFree是配套的釋

55、放內(nèi)存函數(shù);xmlStrcmp是字符串比較函數(shù)等等?;旧蟲mlChar字符串相關(guān)函數(shù)都在xmlstring.h中定義;而動態(tài)內(nèi)存分配函數(shù)在xmlmemory.h中定義。3)xmlChar*與其它類型之間的轉(zhuǎn)換另外要注意,因為總是要在xmlChar*和char*之間進(jìn)行類型轉(zhuǎn)換,所以定義了一個宏BAD_CAST,其定義如下:xmlstring.h#define BAD_CAST (xmlChar *)原則上來說,unsigned char和char之間進(jìn)行強(qiáng)制類型轉(zhuǎn)換是沒有問題的。4)文檔類型xmlDoc、指針xmlDocPtrxmlDoc是一個struct,保存了一個xml的相關(guān)信息,例如文

56、件名、文檔類型、子節(jié)點等等;xmlDocPtr等于xmlDoc*,它搞成這個樣子總讓人以為是智能指針,其實不是,要手動刪除的。xmlNewDoc函數(shù)創(chuàng)建一個新的文檔指針。xmlParseFile函數(shù)以默認(rèn)方式讀入一個UTF-8格式的文檔,并返回文檔指針。xmlReadFile函數(shù)讀入一個帶有某種編碼的xml文檔,并返回文檔指針;細(xì)節(jié)見libxml2參考手冊。xmlFreeDoc釋放文檔指針。特別注意,當(dāng)你調(diào)用xmlFreeDoc時,該文檔所有包含的節(jié)點內(nèi)存都被釋放,所以一般來說不需要手動調(diào)用xmlFreeNode或者xmlFreeNodeList來釋放動態(tài)分配的節(jié)點內(nèi)存,除非你把該節(jié)點從文檔中

57、移除了。一般來說,一個文檔中所有節(jié)點都應(yīng)該動態(tài)分配,然后加入文檔,最后調(diào)用xmlFreeDoc一次釋放所有節(jié)點申請的動態(tài)內(nèi)存,這也是為什么我們很少看見xmlNodeFree的原因。xmlSaveFile將文檔以默認(rèn)方式存入一個文件。xmlSaveFormatFileEnc可將文檔以某種編碼/格式存入一個文件中。5)節(jié)點類型xmlNode、指針xmlNodePtr節(jié)點應(yīng)該是xml中最重要的元素了,xmlNode代表了xml文檔中的一個節(jié)點,實現(xiàn)為一個struct,內(nèi)容很豐富:tree.htypedef struct _xmlNode xmlNode;typedef xmlNode *xmlNod

58、ePtr;struct _xmlNode void *_private;/* application data */ xmlElementType type; /* type number, must be second ! */ const xmlChar *name; /* the name of the node, or the entity */ struct _xmlNode *children;/* parent-childs link */ struct _xmlNode *last; /* last child link */ struct _xmlNode *parent;/

59、* child-parent link */ struct _xmlNode *next; /* next sibling link*/ struct _xmlNode *prev; /* previous sibling link*/ struct _xmlDoc*doc;/* the containing document */ /* End of common part */ xmlNs *ns; /* pointer to the associated namespace */ xmlChar *content; /* the content */ struct _xmlAttr *p

60、roperties;/* properties list */ xmlNs *nsDef; /* namespace definitions on this node */ void *psvi;/* for type/PSVI informations */ unsigned short line; /* line number */ unsigned short extra;/* extra data for XPath/XSLT */;可以看到,節(jié)點之間是以鏈表和樹兩種方式同時組織起來的,next和prev指針可以組成鏈表,而parent和children可以組織為樹。同時還有以下重要元

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論