当前位置: 首页 > 工具软件 > DOM Treemap > 使用案例 >

dom4j读取数的案例

杜英范
2023-12-01

xml文件结构:

currency_field.xml

<?xml version="1.0" encoding="UTF-8"?>
<currency>
 <type name="filed">
     <item name="HKD" ini="0">HKD</item>
     <item name="MOP" ini="1">MOP</item>
     <item name="USD" ini="1">USD</item>
     <item name="JPY" ini="1">JPY</item>
     <item name="TWD" ini="1">TWD</item>
     <item name="CNY" ini="1">CNY</item>
 </type>
</currency>

rove_transaction_ref_type.xml


<?xml version="1.0" encoding="UTF-8"?>
<ref_type>
 <inflow_type>
  <type name="A">
   <item id="1">RIO entertainment Ltd WHB</item>
   <item id="2">CASH</item>
   <item id="3">CASH purchase record</item>
   <item id="4">Cash Ref No</item>
   <item id="5">Cash transaction</item>
   <item id="6">Cashier Order BOC</item>
   <item id="7">Cheque Rio Entertainment Ltd WHB</item>
   <item id="8">Rio Entertainment  Cheque WHB</item>
   <item id="9">CASH purchase record</item> 
   <item id="10">Waldo Marketing Ltd GDB</item>
   <item id="11">Credit Card Receipt</item>
   <item id="12">Credit Card Slip</item>
   <item id="13">Drawee Bank WHB</item>
   <item id="14">MTL Log Attached</item>
   <item id="15">Personal Check BOC</item>
   <item id="16">Personal CQ HSBC</item>
   <item id="17">Purchase Receipt</item></type>
  <type name="B">
   <item id="1">Cash</item>
   <item id="2">Cash PR</item>
   <item id="3">Drawee Bank CHB</item>
   <item id="4">Marketing Waldo  Ltd GDB</item>
   <item id="5">Application for N. NEG. Chips</item>
   <item id="6">Bank Deposit Slip GDB</item>
   <item id="7">Bounced Cheque Standard Chartered Bank</item>
   <item id="8">Cage</item>
   <item id="9">Cash PR</item> 
   <item id="10">Cashier Order HSB</item>
   <item id="11">Cash Ref No.</item>
   <item id="12">Cash Transaction</item>
   <item id="13">Check Citi Bank</item>
   <item id="14">Cheque  on BOC</item>
   <item id="15">Commission buy in PR</item>
   <item id="16">Credit PR</item>
   <item id="17">Credit card purchase</item>
   <item id="18">Credit Drawdown</item>
   <item id="19">Credit Drawdown repayment</item>
   <item id="20">Credit Note BOC</item>
   <item id="21">Depoist receipt</item>
   <item id="22">Deposit Slip BWH</item>
   <item id="23">Deposit Withdraw PR</item>
   <item id="24">Direct Deposit NYB</item>
   <item id="25">Drawn on CHB</item>
   <item id="26">Drawee Bank 39 on</item>
   <item id="27">FM  Tfr Cashier Order BOC</item>
   <item id="28">FM Suspense tranfer on personal CQ BOC</item>
   <item id="29">Fornt Money Buyin</item> 
   <item id="30">Front Money Cash  Buyin</item>
   <item id="31">Front Money Schedule</item>
   <item id="32">Front Money Schedule attached</item>
   <item id="33">Galaxy Casino WHB</item>
   <item id="34">CASH</item>
   <item id="35">Guarantee Deposit PR</item>
   <item id="36">IOU</item>
   <item id="37">IOU</item>
   <item id="38">Luso Cashier Order HCO</item>
   <item id="39">Marketing Waldo Ltd GDB</item>
   <item id="40">Nanyang Commercial Drawee Bank</item>
   <item id="41">Personal Check  CHB</item>
   <item id="42">T/T drawdown</item>
   <item id="43">Waldo Maketing Ltd GDB</item>
   <item id="44">WHBDrawee Bank 004/499 CQ</item>
   <item id="45">Winning CQ  GDB</item>     
  </type>
  <type name="D">
   <item id="1">Account Deposit receipt</item>
   <item id="2">Deposit On</item>
   <item id="3">Deposit Receipt</item>
   <item id="4">FM Suspense Deposit Receipt</item>
   <item id="5">Account deposit</item>
   <item id="6">Account Deposit from</item>
   <item id="7">BOC Cheque deposit</item>
   <item id="8">BOC Deposit Slip#  on Deposit  Receipt</item>
   <item id="9">Cahsier Order BOC</item> 
   <item id="10">Cash</item>
   <item id="11">Cash Chips - Deposit Receipt</item>
   <item id="12">Cash deposit On</item>
   <item id="13">Cash Deposit Receipt</item>
   <item id="14">Cash PR # on deposited rececipt</item>
   <item id="15">Cashier Order HSBC</item>
   <item id="16">Cashier Orde HSB# on deposit receipt</item>
   <item id="17">Cashier Order BTF</item>
   <item id="18">Credit Not BOC</item>
   <item id="19">Demand Deposit BOC</item>
   <item id="20">DEP</item>
   <item id="21">Deposi On</item>
   <item id="22">Deposit Account Form</item>
   <item id="23">Deposit CQ on BOC</item>
   <item id="24">Deposit off</item>
   <item id="25">Deposit off</item>
   <item id="26">Deposit off</item>
   <item id="27">Deposit On</item>
   <item id="28">Deposit on</item>
   <item id="29">Deposit Receipt</item> 
   <item id="30">Deposit Slip BOC</item>
   <item id="31">Drawee Bank 004 -469 on deposit receipt</item>
   <item id="32">FM Deposit</item>
   <item id="33">G. Deposit Receipt</item>
   <item id="34">Personal CQ  HSB</item>
   <item id="35">TT  Drawdown</item>
   <item id="36">Waldo Marketing LTD on GDB</item>
  </type>
  <type name="E">
   <item id="1">Receipt</item>
   <item id="2">Redemption IOU</item>
   <item id="3">Cash</item>
   <item id="4">Cash $1,000,0000; Cashier Order - Public Bank</item>
   <item id="5">Cash chips release authorization attached.</item>
   <item id="6">Cashier Order - Public Bank</item>
   <item id="7">Credit Drandown attached</item>
   <item id="8">Credit Draw down redeemed</item>
   <item id="9">Credit Drawdown</item> 
   <item id="10">Credit Drawdown repayment</item>
   <item id="11">Credit Drawdown Repayment receipt</item>
   <item id="12">Deposit Receipt</item>
   <item id="13">Drawdown Repayment</item>
   <item id="14">IOU</item>
   <item id="15">Original IOU</item>
   <item id="16">Part Redemption</item>
   <item id="17">TT Transfer from WHB</item>
   <item id="18">VIP Monthly Payment</item>
  </type>
  <type name="G">
   <item id="1">Disbursement advice on Rio Entertainment Ltd BWH</item>
   <item id="2">VIP Monthly Payback</item>
  </type>
  <type name="H">
   <item id="1">Receipt # Repayment of credit</item>
   <item id="2">Cash Chips Deposit On</item>
   <item id="3">Cash - Deposit on</item>
   <item id="4">Cash and cash chips Deposit on</item>
   <item id="5">Cash Chips from other Galaxy property Deposit Receipt</item>
   <item id="6">Cashier Order BNU # on Deposit Receipt</item>
   <item id="7">Chip Deposit On</item>
   <item id="8">Credit Drawdown notice</item>
   <item id="9">Credit Drawdown repayment</item> 
   <item id="10">Credit repayment  notice</item>
   <item id="11">Deposit Receipt</item>
   <item id="12">Inward T/T drawdown</item>
   <item id="13">NNP Chip Deposit on</item>
   <item id="14">Personal CQ LIB# on deposit On</item>
   <item id="15">Premium Chips Deposit On</item>
  </type>
  <type name="K">
   <item id="1">Cash transaction</item>
   <item id="2">CAPTURED VIA MTL</item>
   <item id="3">Cash</item>
   <item id="4">Cash chip return</item>
   <item id="5">Cash out Transaction slips</item>
   <item id="6">Cash PR</item>
   <item id="7">Cash Premium Player Settlement Sheet</item>
   <item id="8">Cash Ref No.</item>
   <item id="9">Cashier Order BOC</item> 
   <item id="10">Cashier Order GDB</item>
   <item id="11">Drawee Bank HSBC</item>
   <item id="12">Front Money Schedule attached</item>
   <item id="13">MTL Log Attached</item>
   <item id="14">Non Winning CQ  Cashier Order WHB</item>
   <item id="15">Personal CH  CHB</item>
   <item id="16">Return of Cash Chips</item>
   <item id="17">Settlement Cash Chips</item>
   <item id="18">Waldo Maketing Ltd GDB</item>
   <item id="19">Winning Check Galaxy Casino WHB</item>
  </type>
  <type name="L">
   <item id="1">Cash</item>
   <item id="2">Cash  Chips Transaction</item>
   <item id="3">Cash  Non Neg. Return</item>
   <item id="4">Non Neg Return</item>
   <item id="5">Non Neg. Return</item>
   <item id="6">Redemption of non-negotiable chips</item>
  </type>
 </inflow_type>
 <outflow_type>
  <type name="N">
   <item id="1">Deposit receipt</item>
   <item id="2">Account  Deposit receipt</item>
   <item id="3">Account Deposit form</item>
   <item id="4">Cash</item>
   <item id="5">Cashier order BOC</item>
   <item id="6">Cashier order BOC</item>
   <item id="7">RIO entertainment Ltd WHB</item>
   <item id="8">CASH</item>
   <item id="9">CASH purchase record</item> 
   <item id="10">RIO entertainment Ltd WHB</item>
   <item id="11">CASH</item>
   <item id="12">CASH purchase record</item>
   <item id="13">RIO entertainment Ltd WHB</item>
   <item id="14">CASH</item>
   <item id="15">CASH purchase record</item>
   <item id="16">RIO entertainment Ltd WHB</item>
   <item id="17">CASH</item>
   <item id="18">RIO entertainment Ltd WHB</item>
   <item id="19">CASH</item>
   <item id="20">CASH</item>
   <item id="21">CASH purchase record</item>
   <item id="22">CASH</item>
   <item id="23">CASH purchase record</item>
   <item id="24">RIO entertainment Ltd WHB</item>
   <item id="25">CASH</item>
   <item id="26">CASH purchase record</item>  
  </type>
  <type name="O">
   <item id="1">RIO entertainment Ltd WHB</item>
   <item id="2">CASH</item>
   <item id="3">CASH purchase record</item>
   <item id="4">RIO entertainment Ltd WHB</item>
   <item id="5">CASH</item>
   <item id="6">CASH purchase record</item>
   <item id="7">RIO entertainment Ltd WHB</item>
   <item id="8">CASH</item>
   <item id="9">CASH purchase record</item> 
   <item id="10">RIO entertainment Ltd WHB</item>
   <item id="11">CASH</item>
   <item id="12">CASH purchase record</item>
   <item id="13">RIO entertainment Ltd WHB</item>
   <item id="14">CASH</item>
   <item id="15">CASH purchase record</item>
  </type>
  <type name="P">
   <item id="1">RIO entertainment Ltd WHB</item>
   <item id="2">CASH</item>
   <item id="3">CASH purchase record</item>
   <item id="4">RIO entertainment Ltd WHB</item>
   <item id="5">CASH</item>
  </type>
  <type name="Q">
   <item id="1">RIO entertainment Ltd WHB</item>
   <item id="2">CASH</item>
   <item id="3">CASH purchase record</item>
   <item id="4">RIO entertainment Ltd WHB</item>
   <item id="5">CASH</item>
   <item id="6">CASH purchase record</item>
   <item id="7">RIO entertainment Ltd WHB</item>
   <item id="8">CASH</item>
   <item id="9">CASH purchase record</item> 
   <item id="10">RIO entertainment Ltd WHB</item>
   <item id="11">CASH</item>
   <item id="12">CASH purchase record</item>
  </type>
  <type name="R">
   <item id="1">RIO entertainment Ltd WHB</item>
   <item id="2">CASH</item>
   <item id="3">CASH purchase record</item>
   <item id="4">RIO entertainment Ltd WHB</item>
   <item id="5">CASH</item>
  </type>
  <type name="S">
   <item id="1">RIO entertainment Ltd WHB</item>
   <item id="2">CASH</item>
   <item id="3">CASH purchase record</item>
  </type>
  <type name="T">
   <item id="1">RIO entertainment Ltd WHB</item>
   <item id="2">CASH</item>
  </type>
  <type name="U">
   <item id="1">RIO entertainment Ltd WHB</item>
   <item id="2">CASH</item>
   <item id="3">CASH purchase record</item>
   <item id="4">RIO entertainment Ltd WHB</item>
   <item id="5">CASH</item>
   <item id="6">CASH purchase record</item>
   <item id="7">RIO entertainment Ltd WHB</item>
   <item id="8">CASH</item>
   <item id="9">CASH purchase record</item> 
   <item id="10">RIO entertainment Ltd WHB</item>
  </type>
   </outflow_type>
</ref_type>

package com.nikoyo.custom.galaxy.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import org.dom4j.io.SAXReader;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;

public class RefType {
 
 public static String getRefType(String type,String item) throws DocumentException {
  SAXReader sr = new SAXReader();
  Document doc = sr.read(RefType.class.getClassLoader().getResource(("/rove_transaction_ref_type.xml")));
  Element root = doc.getRootElement();
  List list = new ArrayList();
  StringBuffer typePtion = new StringBuffer("<select style='width:160;align:middle' >");
  if(isInflowType(type))
      list = root.selectNodes("/ref_type/inflow_type/type[@name='" + type+ "']/item");
  if(isOutflowType(type))
   list = root.selectNodes("/ref_type/outflow_type/type[@name='" + type+ "']/item");
  Iterator iterator = list.iterator();
  System.out.print(list);
  while (iterator.hasNext()) {
   Element node = (Element) iterator.next();
   if(item!=null&&item.equals(node.attribute("id").getStringValue()))
       typePtion.append("<option value='"+node.attribute("id").getStringValue()+"' selected>"+node.getText()+"</option>");
   else{
    typePtion.append("<option value='"+node.attribute("id").getStringValue()+"'>"+node.getText()+"</option>");
   }
  }
  typePtion.append("</select>");
  return typePtion.toString();
 }
 private static Map<String,Set<String>> getRefType() throws DocumentException {
  SAXReader sr = new SAXReader();
  Map<String,Set<String>> map = new HashMap<String,Set<String>>();
  Document doc = sr.read(RefType.class.getClassLoader().getResource(("/rove_transaction_ref_type.xml")));
  Element root = doc.getRootElement();
  List list = root.selectNodes("/ref_type/inflow_type/type");
  Iterator iterator = list.iterator();
  Set<String> inflowSet =  new HashSet<String>();
  while (iterator.hasNext()) {
   Element node = (Element) iterator.next();
   inflowSet.add(node.attribute("name").getStringValue());
  }
  map.put("inflow_type", inflowSet);
  list= root.selectNodes("/ref_type/outflow_type/type");
  iterator = list.iterator();
  Set<String> outflowSet =  new HashSet<String>();
  while (iterator.hasNext()) {
   Element node = (Element) iterator.next();
   outflowSet.add(node.attribute("name").getStringValue());
  }
  map.put("outflow_type", outflowSet);
  return map;
 }
 public  static String   getCurrencyType(String field) throws DocumentException {
  StringBuffer option= new StringBuffer("<select style='width:80;align:middle' >");
  System.out.println("3333");
  SAXReader sr = new SAXReader();
  System.out.println(RefType.class.getClassLoader().getResource(("currency_field.xml")));
  Document doc = sr.read(RefType.class.getClassLoader().getResource(("/currency_field.xml")));
  Element root = doc.getRootElement();
  List list = root.selectNodes("/currency/type/item");
  Iterator iterator = list.iterator();
  field =field.trim();
  if(field==null||field.equals("")){
   while (iterator.hasNext()) {
    Element node = (Element) iterator.next();
    if(node.attribute("ini").getStringValue().equals("0")){
     option.append("<option value='"+node.attribute("name").getStringValue()+"'  selected>"+node.getText()+"</option>");
    }
    else{
    option.append("<option value='"+node.attribute("name").getStringValue()+"'>"+node.getText()+"</option>");
    }
   }
  }else{
   while (iterator.hasNext()) {
    Element node = (Element) iterator.next();
    String name = node.attribute("name").getStringValue();
    if(field.equals(name)){
     option.append("<option value='"+name+"'   selected>"+node.getText()+"</option>");
    }
    else
    {
     option.append("<option value='"+name+"'>"+node.getText()+"</option>");
    }
   }
   
  }
    option.append("</select>");
  return option.toString();
 }
 
 public static boolean isOutflowType(String type) throws DocumentException{
  Map<String,Set<String>> map = getRefType();
  Set<String> setOutflow = map.get("outflow_type");
  if(setOutflow.contains(type)){
   return true;
  }
  return false;
 }
 public static boolean isInflowType(String type) throws DocumentException{
  Map<String,Set<String>> map = getRefType();
  Set<String> setInflow = map.get("inflow_type");
  if(setInflow.contains(type)){
   return true;
  }
  return false;
 }
 public static String getType(String type) throws DocumentException{
  Map<String,Set<String>> map = getRefType();
  StringBuffer option= new StringBuffer("<select style='width:80;align:middle' >");
  Set<String> setinflow = map.get("inflow_type");
  Object[]  inflow_type =  map.get("inflow_type").toArray();
  Arrays.sort(inflow_type);

  System.out.println("set  "+inflow_type);
  Object[] setoutflow =map.get("outflow_type").toArray();
  Arrays.sort(setoutflow);
  //String strType = "";
  for(Object strType:inflow_type){
   System.out.print(strType);
   if(type!=null&&type.equals(strType)){
       option.append("<option value='"+strType+"'   selected>"+strType+"</option>");
   }
   else{
    option.append("<option value='"+strType+"'>"+strType+"</option>");
   }
  }
  for(Object strType:setoutflow){
   if(type!=null&&type.equals(strType)){
       option.append("<option value='"+strType+"'   selected>"+strType+"</option>");
   }
   else{
    option.append("<option value='"+strType+"'>"+strType+"</option>");
   }
  }
  option.append("</select>");
  System.out.print(option.toString());
  return option.toString();
 }
 
 public static void main(String[] arg) throws DocumentException {
  System.out.println(RefType.getType(""));
 }
}

转载于:https://www.cnblogs.com/mostearth/archive/2011/04/18/2020237.html

 类似资料: