linux C語言學習筆記

2021-10-01 01:45:11 字數 1811 閱讀 7855

linux下用c語言解析xml

解析的xml檔案內容(test.xml)

<?xml version="1.0" encoding="iso-8859-1"?>

第一步:在linux下部署解析xml所有的環境

2)解壓壓縮包

tar zxvf libxml2-2.9.9.tar.gz

進入解壓後的目錄

cd libxml

3)編輯命令

./configure (注意:如果configure檔案沒有可執行許可權,增加可執行許可權)

make

make install

安裝的目錄在 /usr/local/include/libxml2目錄下,libxml2相關的庫檔案應該在/usr/local/lib目錄下。

第二步:編寫test.c檔案

#include #include #include #include void main()

curnode = xmldocgetrootelement(doc); //確定文件根元素

if (null == curnode)

printf("node name is %s!\n", curnode->name);

if (xmlstrcmp(curnode->name, bad_cast "test"))

curnode = curnode->xmlchildrennode; //子節點集是鍊錶

xmlnodeptr propnodeptr = curnode;

while(curnode != null)

//查詢帶有屬性attribute的節點

if (xmlhasprop(curnode,bad_cast "conf"))

curnode = curnode->next;

}//查詢屬性

xmlattrptr attrptr = propnodeptr->properties; //屬性集是鍊錶

while (attrptr != null)

{if (!xmlstrcmp(attrptr->name, bad_cast "resetconf"))

{xmlchar* lsattr = xmlgetprop(propnodeptr,bad_cast "resetconf");

//szattr要呼叫函式xmlfree(lsattr)手動刪除否則會發生記憶體洩露。

//cout<<"get attribute = "{

xmlchar* lsattr = xmlgetprop(propnodeptr,bad_cast "testname");

//szattr要呼叫函式xmlfree(lsattr)手動刪除否則會發生記憶體洩露。

//cout<<"get attribute = "《第三步:編譯並執行

編譯:gcc test.c -o test -lxml2 -i/usr/include/libxml2

執行./test

注:可在makefile檔案裡,新增引用路徑

automake_options = foreign subdir-objects

libs=-lncurses -lpthread -lm -lpq

ldflags=-l. $(system_ldflags)

test_sources = test.c

test_cflags  = $(am_cflags) -i/usr/local/include/libxml2  -l/usr/local/lib -lxml2

test_ldflags = $(am_ldflags) $(ldflags) $(libs)

Linux C語言學習筆記1

1 網路配置 虛擬機器 設定 網路介面卡 橋接 適用於網路環境有路由器,可分配多個ip nat 只有乙個ip 2 更新軟體列表 sudo apt get update 如果殘留鎖檔案 刪除方法 sudo rm 鎖檔案路徑 更改為中國伺服器 ubuntu software center edit so...

Linux C語言學習筆記3

1 整型資料 1.整型變數int int a 定義了一塊記憶體,記憶體的名字叫a,用來存放整型資料 2.負數在計算機中的儲存形式 0000 0010 2 0是符號位,代表正整數 1000 0010 2 1是符號位,代表負整數 但在計算機記憶體中,負數是以補碼的形式儲存的 即,將 1000 0010 ...

linux c語言學習筆記之守護程序

守護程序 概述 守護程序 daemon 是生存期長的一種程序。它們常常在系統引導裝入時起動,在系統關閉時終止。因為它們沒有控制終端,所以說它們是在後台執行的。linux 系 統有很多守護程序,它們執行日常事物活動。所有守護程序都以超級使用者 使用者i d 為0 的優先權執行。沒有乙個守護程序具有控制...