原創 我自己的XML處理類 功能較多但有侷限性

2021-03-31 08:57:01 字數 2915 閱讀 1007

package jdom;

/*新聞專用xml類檔案

功能:刪除由上到下

新增在最下面新增

讀取由下向上

可以跟據id刪除記錄

可以由上到下刪除x條記錄

新增時可以限制記錄多少,多於時刪除舊的再插入新資料

全程資料交換使用arraylist 方便處理

不滿意:

擴充套件性不強針對特定的xml檔案,沒能無限級訪問子節點,效能還沒得優化!

public class writexml

public void addxml() throws exception//向xml新增乙個結點

else

}int a = postlist.size() / 5;//要存放的記錄個數

int b = maxline - docline;//空位

if(a >= maxline)//如果需要新增的記錄多於最大數目

a = maxline;//存放記錄至於最大數目

if(a < 0)

a = postlist.size() / 5;

if(a - b >= 0)

// for(int i = 0; i < (a * 5); i = i + 5)

for(int i = (a * 5)-1; i >= 0; i = i - 5)

this.public_doc = read_doc;

}public int get_docline()

public int get_maxline()

}this.map = a;

}public arraylist readxml_one(string id) throws exception//讀取記錄的id的節點記錄

}return a;

}public arraylist readxml_all(int number) throws exception//讀取記錄的所有記錄

return a;

}public arraylist readxml_all_id(int number) throws exception//讀取記錄的所有記錄

return a;

}public void editxml(string id) throws exception//修改記錄是id的節點}}

public boolean delxml(string id) throws exception//跟據id修改指定的記錄

}this.public_doc = read_doc;

return tmpbool;

}public boolean delxml(int number) throws exception//刪除xml中資料最後的number條記錄

this.public_doc = read_doc;

return tmpbool;

}public void wreitxml_file() throws exception//生成檔案到硬碟

format format = format.get***pactformat();

format.setencoding("gb2312");           //設定xml檔案的字元為gb2312

format.setindent("    ");               //設定xml檔案的縮排為4個空格

xmloutputter xmlout = new xmloutputter(format);//在元素後換行,每一層元素縮排四格

xmlout.output(public_doc, new fileoutputstream(get_fullrootfile()));

//從硬碟中取數資料到記憶體

public boolean readxml() throws exception

catch(exception e)

}public void set_postlist(arraylist postlist)

public void initialize(string url)

public void initialize(pagecontext pagecontext)

public void set_maxlint(int max)

public void setxmlfilename(string filename)

else

}public void firstdir(string rot)

public void creatdir()catch(exception e)

}public void setsecon_root(string secon_root)

public map getinputmap()

public string getstring(string key)

}用於管理兩個xml檔案第乙個(這個xml存放第二個xml的路徑):

<?xml version="1.0" encoding="gb2312"?>

defail

xml/x02.xml

xml/x02.xml

nofile

nofile

xml/x05.xml

nofile

xml/x07.xml

xml/x08.xml

nofile 1

nofile

xml/1/x02.xml

nofile

nofile

xml/1/x05.xml

nofile

nofile

nofile

nofile

第二個(存放一些新聞基本資訊):

<?xml version="1.0" encoding="gb2312"?>

22title

file.htm

2005-01-25 23:51:52.0

3

我自己的超強的XML文件加密類

using system using system.io using system.security.cryptography using system.xml using system.data namespace hxh.api this.iv new byte get the key and ...

原創 我自己想的幾道入門PHP筆試題

我自己想的幾道入門php筆試題,沒有什麼意義,只是自己隨便想想,算是好玩。一 基礎題 1.寫出如下程式的輸出結果 str1 null str2 false echo str1 str2 相等 不相等 str3 str4 0 echo str3 str4 相等 不相等 str5 0 str6 0 ec...

原創 我自己想的幾道入門PHP筆試題

我自己想的幾道入門php筆試題,沒有什麼意義,只是自己隨便想想,算是好玩。一 基礎題 1.寫出如下程式的輸出結果 str1 null str2 false echo str1 str2 相等 不相等 str3 str4 0 echo str3 str4 相等 不相等 str5 0 str6 0 ec...