LAST UPDATE: July 2009

Sample code:


import java.io.*;
import java.util.*;
import org.teldap.core.xmlvalidator.unionCatalog.DACatalogXMLParser;

/**
* Copyright 2009 數位典藏與數位學習國家型科技計畫(TELDAP) 數位核心平台計畫
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*
* @author 徐慈妍、洪崇熙、洪國翔
* @version 1.0
*/
public class sample {
  
  /*
   * 檢查單一個DACatalog XML
   */
  public void validateDACatalogXML(File xmlfile){
    
      DACatalogXMLParser XMLParser = new DACatalogXMLParser(xmlfile.getAbsolutePath());
      XMLParser.xmlValidate(xmlfile); //執行DACatalog XML規則檢查,包含全部的檢查程序

      TreeMap errors=new TreeMap(XMLParser.getInvalidateMsg()); //取得檢查後的錯誤訊息
      Iterator iterator=errors.keySet().iterator(); //取得錯誤訊息代碼
      while(iterator.hasNext()){
            Integer errCode=(Integer)iterator.next();  
            System.out.println("\n錯誤訊息代碼:"+errCode);
            ArrayList detail=(ArrayList)errors.get(errCode); 
            for(int i=0;detail!=null && i<detail.size();i++){    //列出更詳細的錯誤說明訊息
                System.out.println((String)detail.get(i));
            }
      }
  }
  
  
  /*
   * 程式執行進入點
   */
  public static void main(String[] strs){
    sample sample=new sample();
    sample.validateDACatalogXML(new File("resources/test.xml"));
  }

}
converted by Java2html

使用步驟:Command Line檢查單一個DACatalog XML文件

  1. 確定已安裝Java SE Development Kit (JDK)
  2. 請下載sample_code.zip
  3. CMD編譯(CMD路徑切換到sample_code資料夾內):
    ...\sample_code> javac -classpath jar/jdom.jar;jar/DACatalogXMLValidator.jar sample.java
    附註:編譯跟執行sample.java時,需要特地附加的jar檔,皆包含在sample_code/jar資料夾內。測試使用的XML檔則包含在sample_code/resources資料夾內。
  4. 編譯後會產生sample.class檔,再用CMD執行(CMD路徑切換到sample_code資料夾內):
    ...\sample_code> java -classpath jar/jdom.jar;jar/DACatalogXMLValidator.jar sample
  5. 輸出結果(錯誤訊息代碼說明請參照: error_code_description.html)
  6. 錯誤訊息代碼:301
    /DACatalog/AdminDesc/Project[@Creator]
    /DACatalog/AdminDesc/Project[@GenDate]
    錯誤訊息代碼:4021
    錯誤訊息代碼:4023
    錯誤訊息代碼:4032
    http://210.241.17.253/hakkaculfront/search/image_view.jsp?fileName=1MLHM-5040121.135-0001-i.jpg
    錯誤訊息代碼:40321
    http://210.241.17.253/hakkaculfront/search/image_view.jsp?fileName=1MLHM-5040121.135-0001-i.jpg