XML to XML 轉換的類

2021-08-24 21:56:55 字數 2883 閱讀 8866

/**

* * title: parser類

* *

* description: xml之間轉換主類

* *

* *

* * 

* @version 1.0

*/public class parser

/*** 設定規則檔案schema的絕對路徑

* @param ruleschemapath

*/public void setruleschemapath(string ruleschemapath)

public document getdoc()

public void setdoc(document doc)

public string getsourcepath()

/*** 設定源xml檔案的絕對路徑

* @param sourcepath

*/public void setsourcepath(string sourcepath)

public string gettargetfilefullname()

/*** 設定要生成的目標xml檔案的名稱,是絕對路徑

* @param targetfilefullname 要生成的目標xml檔案的絕對路徑

*/public void settargetfilefullname(string targetfilefullname)

public string getrulepath()

/*** 設定規則檔案的絕對路徑

* @param rulepath 規則檔案的絕對路徑

*/public void setrulepath(string rulepath)

public parser()

/*** 從乙個檔案路徑裡讀取乙個document

* @param filename 檔案的絕對路徑

* @return document

*/private document read(string filename) catch (documentexception e)

return document;

}/**

* 根據schema檔案驗證規則檔案是否合法,如果合法,返回true;否則返回false.

* @param xsdpath  schema檔案的絕對路徑

* @param xmlpath  欲驗證的xml檔案的絕對路徑

* @return 如果xml檔案符合指定的schema檔案要求,返回true;否則返回false.

*/private boolean validatexmlbyxsd(string xsdpath,string xmlpath)

saxparse***ctory factory = saxparse***ctory.newinstance();

factory.setnamespaceaware(true);

factory.setvalidating(true);

try catch (parserconfigurationexception e) catch (saxexception e) catch (ioexception e)

return isok;

}/**

* 讀取規則檔案和原始檔生成目標檔案的document

* @return 目標檔案的document.

*/private document parserulexml()

public void setparentfrom(string parentfrom)

public string getfrom()

public void setfrom(string from)

public string getparentto()

public void setparentto(string parentto)

public string getto()

public void setto(string to)

public void setfromdocument(document source)

public document getfromdocument()

public void settargetdocument(document doc)

/*** 根據規則檔案生成目標檔案的document

* @return

*/public document gettargetdocument() else

try catch (exception e)

} else

try catch (exception e)

}else if(this.parentto != null)else

}else

new exception("必須要有子路徑!");

} else

try catch (exception e)

}string parents = parentpath.substring(1).split(staticconstant.slash);

string temp = "";

element parentelement = null;

for(int i=0,l=parents.length;i/**

* * title: staticconstant類

* *

* description: 靜態常量

* * **

* * 

* @version 1.0

*/public class staticconstant

測試類public class maintest extends  testcaseelse

}

類的自動轉換

說明 c 允許程式設計師指定類之間進行轉換的方式 含基本型別 站在類的角度看問題,姑且分為 當前類 和 其他類 假設 當前類是程式設計師定義的,其他類既可以是程式設計師定義的,也可以是c 內建的基本型別 方式 通過定義 轉化函式 轉化函式 本質 允許只傳入乙個實參的建構函式 包括 1.只接受乙個引數...

拼音轉換類

php 漢字轉拼音 author jerryli hzjerry gmail.com version v0.20140715 package spfw.core.lib.final global sea php fw var env example echo cutf8 py encode 阿里巴巴...

派生類到基類的轉換 和基類到派生類的轉換

一 基類與派生類的轉換 3種繼承方式 公用 保護 私有繼承 中,公用派生類才是基類真正的子型別,它完整地繼承了基類的功能。不同型別資料之間在一定條件下可以進行型別的轉換。基類與派生類物件之間是否也有賦值相容的關係,可否進行型別間的轉換?回答是可以的。基類與派生類物件之間有賦值相容關係,由於派生類中包...