dom解析xml格式的字串示例

2021-08-02 12:47:50 字數 4856 閱讀 3201

/** *

* the class quasiaction.

* * @explain 由於公司保密要求,敏感資訊已經去除(比如:class路徑,注釋資訊,作者,時間等。。。。。。)

xml = request.getparameter("xml名稱");

if (xmlxml == null) {

xml = (string) request.getsession(true)

getattribute("xml名稱");

if (xmlxml == null) {

throw new exception("獲取引數為空");

document doc = xmlutil.par***mltext(xml);

element element = doc.getdocumentelement();

nodelist nodelist = element.getchildnodes();

for (int i = 0; i < nodelist.getlength(); i++) {

node nodeone = nodelist.item(i);

if (nodeone.getnodetype() != node.element_node) {

continue;

使用者賬號

if (i == 0) {

if ("userid".equals(nodeone.getnodename())) {

if ("null".equals(nodeone.getfirstchild()

getnodevalue())) {

throw new exception("使用者賬號必須填寫,不能為空");

else if (nodeone.getfirstchild().getnodevalue()

indexof1) {

throw new exception("使用者賬號含有非法字元");

qb.setuserid(dxd.forcestring(nodeone.getfirstchild()

getnodevalue()));

else {

throw new exception(

xml格式異常,頂層元素[cstmroot]下的第1個子元素--使用者賬號[code]元素未找到");

機構**

if (i == 1) {

if ("agencycode".equals(nodeone.getnodename())) {

if ("null".equals(nodeone.getfirstchild()

getnodevalue())) {

throw new exception("機構**必須填寫,不能為空");

else if (nodeone.getfirstchild().getnodevalue()

indexof1) {

throw new exception("機構**含有非法字元");

qb.setagencycode(dxd.forcestring(nodeone

getfirstchild().getnodevalue()));

else {

throw new exception(

xml格式異常,頂層元素[cstmroot]下的第2個子元素--機構**[agencycode]元素未找到");

同步時間

if (i == 2) {

if ("lastsynctime".equals(nodeone.getnodename())) {

if (dxd.checkdatetime(nodeone.getfirstchild()

getnodevalue()) == false) {

throw new exception("同步時間格式錯誤");

else if ("null".equals(nodeone.getfirstchild()

getnodevalue())) {

throw new exception("同步時間必須填寫");

qb.setlastsynctime(dxd.forcestring(nodeone

getfirstchild().getnodevalue()));

else {

throw new exception(

xml格式異常,頂層元素[cstmroot]下的第3個子元素--同步時間[lastsynctime]元素未找到");

準客戶基本資訊

if (i == 3) {

if ("clientbase".equals(nodeone.getnodename())) {

nodelist onelist = nodeone.getchildnodes();

for (int l = 0; l < onelist.getlength(); l++) {

node listfour = onelist.item(l);

if (listfour.getnodetype() != node.element_node) {

continue;

客戶編號

if (l == 0) {

if ("code".equals(listfour.getnodename())) {

if (!"null".equals(listfour.getfirstchild()

getnodevalue())) {

if (listfour.getfirstchild()

getnodevalue().indexof1) {

throw new exception(

準客戶基本資訊的客戶編號含有非法字元");

bb.setcode(dxd.forcestring(listfour

getfirstchild().getnodevalue()));

else {

throw new exception(

xml格式異常,準客戶基本資訊中,父元素[clientbase]下的第1個子元素--客戶編號[code]元素未找到");

客戶名稱

if (l == 1) {

if ("name".equals(listfour.getnodename())) {

if (listfour.getfirstchild().getnodevalue()

indexof1) {

throw new exception(

準客戶基本資訊的客戶名稱含有非法字元");

bb.setname(dxd.forcestring(listfour

getfirstchild().getnodevalue()));

else {

throw new exception(

xml格式異常,準客戶基本資訊中,父元素[clientbase]下的第2個子元素--客戶名稱[name]元素未找到");

移動**(手機號碼)

if (l == 2) {

if ("phone".equals(listfour.getnodename())) {

if ("null".equals(listfour.getfirstchild()

getnodevalue())) {

throw new exception("準客戶基本資訊的移動**必須填寫");

else if (dxd.isphone(listfour

getfirstchild().getnodevalue()) == false) {

throw new exception("移動手機號碼格式錯誤");

else if (listfour.getfirstchild()

getnodevalue().indexof1) {

c格式化字串

格式化字串 以c 的名義 zt 2009 12 22 10 59 從第一堂c語言課上的那個printf開始,格式化字串就成了我的夢魘。此後我還在很多地方遇到過它們 fprintf,sscanf以及cstring的format成員函式 除了能記住 s string的縮寫 代表字串,d decimal的...

字串的處理

一 查詢 1 比較兩個字串大小 int comparison char a,char b 3 在主串中查詢乙個字元 二 替換 1 只替換第一次出現的乙個 2 要全部替換 三 複製 1 乙個串全部複製到另乙個空串中 2 乙個串中的一部分字元 子串 複製到另乙個空串中 3 把乙個串中的一部分字元 子串 ...

shell字串的擷取

shell字串的擷取的問題 一 linux shell 擷取字元變數的前8位,有方法如下 substr a 1 8 a awk a cut c1 8 a a dd bs 1 count 8 2 dev null 二 按指定的字串擷取 1 第一種方法 從左向右擷取最後乙個string後的字串 從左向右...