<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    飛艷小屋

    程序--人生--哲學(xué)___________________歡迎艷兒的加入

    BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
      52 Posts :: 175 Stories :: 107 Comments :: 0 Trackbacks

    package jp.co.nec.ome.utility.xml;

    import java.io.*;
    import javax.xml.parsers.*;

    import org.w3c.dom.*;
    import org.xml.sax.*;

    //*****************************************************************************
    /**
    ?* XML文書分析クラスです。<BR>
    ?* XMLに記述されている定義を分析し、子要素や子要素の內(nèi)容の取扱を容易にする
    ?* ユーティリティクラスです。
    ?* <P>
    ?* @author? Hisaya Saito
    ?* @version $Revision:?? 5.2? $ $Date:?? 20 May 2005 10:24:55? $
    ?* @since?? OpenMeisterEnterprise/EF 3.2
    ?*/
    //*****************************************************************************
    public class OmXMLAnalyzer {

    ? //***************************************************************************
    ? //コンストラクタ
    ? //***************************************************************************

    ? //***************************************************************************
    ? /**
    ?? * privateのコンストラクタです。<BR>
    ?? * スタティックメソッドのみの利用とし、インスタンス化は不許可とします。
    ?? */
    ? //***************************************************************************
    ? private OmXMLAnalyzer() {
    ? }

    ? //***************************************************************************
    ? //publicメソッド
    ? //***************************************************************************

    ? //***************************************************************************
    ? /**
    ?? * XMLファイルパスの文字列からXML文書のルート要素を取得します。
    ?? * @param? argFilePath XMLファイルパス
    ?? * @return ルート要素
    ?? * @exception FileNotFoundException 何らかの理由でファイルを開くことができない場合
    ?? * @exception ParserConfigurationException 要求された構(gòu)成を満たすDocumentBuilderを生成できない場合
    ?? * @exception SAXException 構(gòu)文解析エラーが発生した場合
    ?? * @exception IOException 入出力エラーが発生した場合
    ?? */
    ? //***************************************************************************
    ? public static Element getRootElement(String argFilePath)
    ?????????????????????????????????????????? throws FileNotFoundException,
    ????????????????????????????????????????????????? ParserConfigurationException,
    ????????????????????????????????????????????????? SAXException,
    ????????????????????????????????????????????????? IOException {

    ??? Element rootElement = null;

    ??? //XML文書解釈のためのParserの作成
    ??? File defineFile = new File(argFilePath);
    ??? InputStream inputStream = new FileInputStream(defineFile);
    ??? try {
    ????? DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    ????? DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    ????? Document document = documentBuilder.parse(inputStream);

    ????? //XML文書のツリーの最上位の要素rootを取得します。
    ????? rootElement = document.getDocumentElement();
    ??? } finally {
    ????? inputStream.close();
    ??? }
    ??? return rootElement;
    ? }

    ? //***************************************************************************
    ? /**
    ?? * 入力ストリームからXML文書のルート要素を取得します。
    ?? * @param? argInputStream
    ?? * @return ルート要素
    ?? * @exception FileNotFoundException 何らかの理由でファイルを開くことができない場合
    ?? * @exception ParserConfigurationException 要求された構(gòu)成を満たすDocumentBuilderを生成できない場合
    ?? * @exception SAXException 構(gòu)文解析エラーが発生した場合
    ?? * @exception IOException 入出力エラーが発生した場合
    ?? */
    ? //***************************************************************************
    ? public static Element getRootElement(InputStream argInputStream)
    ????? throws FileNotFoundException,
    ???????????? ParserConfigurationException,
    ???????????? SAXException,
    ???????????? IOException {

    ??? Element rootElement = null;

    ??? //XML文書解釈のためのParserの作成
    ??? try {
    ????? DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    ????? DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    ????? Document document = documentBuilder.parse(argInputStream);

    ????? //XML文書のツリーの最上位の要素rootを取得します。
    ????? rootElement = document.getDocumentElement();
    ??? } finally {
    ????? argInputStream.close();
    ??? }
    ??? return rootElement;
    ? }

    ? //***************************************************************************
    ? /**
    ?? * 指定した親要素の中で最初の子要素を取得します。
    ?? * @param? argParentElement??? 親要素
    ?? * @param? argChildElementName 子要素名
    ?? * @return 最初に取得できた子要素
    ?? */
    ? //***************************************************************************
    ? public static Element getChildElement(Element argParentElement,
    ??????????????????????????????????????? String argChildElementName) {
    ??? return getChildElement(argParentElement, argChildElementName, 0);
    ? }

    ? //***************************************************************************
    ? /**
    ?? * 指定した親要素の中の指定した順番の子要素を取得します。
    ?? * @param? argParentElement?????? 親要素
    ?? * @param? argChildElementName???????? 子要素名
    ?? * @param? argSpecificationNumber 順番
    ?? * @return 指定した順番の子要素
    ?? */
    ? //***************************************************************************
    ? public static Element getChildElement(Element argParentElement,
    ??????????????????????????????????????? String argChildElementName,
    ??????????????????????????????????????? int argSpecificationNumber) {
    ??? NodeList childNodeList =
    ??????????????????? argParentElement.getElementsByTagName(argChildElementName);
    ??? return (Element)childNodeList.item(argSpecificationNumber);
    ? }

    ? //***************************************************************************
    ? /**
    ?? * 指定した親要素の中の全ての子要素を配列で取得します。
    ?? * @param? argParentElement?????? 親要素
    ?? * @param? argChildElementName??? 子要素名
    ?? * @return 子要素の配列
    ?? */
    ? //***************************************************************************
    ? public static Element[] getChildElementList(Element argParentElement,
    ????????????????????????????????????????????? String argChildElementName) {
    ??? NodeList childNodeList =
    ??????????????????? argParentElement.getElementsByTagName(argChildElementName);
    ??? int listCount = childNodeList.getLength();
    ??? if(listCount == 0) {
    ????? return null;
    ??? }
    ??? Element[] childElementList = new Element[listCount];
    ??? for (int i0 = 0; i0 < listCount; i0++) {
    ????? childElementList[i0] = (Element)childNodeList.item(i0);
    ??? }
    ??? return childElementList;
    ? }

    ? //***************************************************************************
    ? /**
    ?? * 指定した要素の中で指定する屬性の値が設(shè)定されている子要素を取得します。
    ?? * @param? argParentElement??? 親要素
    ?? * @param? argChildElementName 子要素名
    ?? * @param? argAttributeName??? 屬性名
    ?? * @param? argAttributeValue?? 屬性の値
    ?? * @return 指定する屬性の値が設(shè)定されている子要素で最初に取得できたもの
    ?? */
    ? //***************************************************************************
    ? public static Element getChildElement(Element argParentElement,
    ??????????????????????????????????????? String argChildElementName,
    ??????????????????????????????????????? String argAttributeName,
    ??????????????????????????????????????? String argAttributeValue) {

    ??? NodeList childNodeList = argParentElement.getElementsByTagName(argChildElementName);
    ??? int listLength = childNodeList.getLength();
    ??? if(listLength == 0) {
    ????? return null;
    ??? }
    ??? Element childElement = null;
    ??? for (int i0 = 0; i0 < listLength; i0++) {
    ????? Element localChildElement = (Element)childNodeList.item(i0);
    ????? String attributeValue = localChildElement.getAttribute(argAttributeName);
    ????? if (attributeValue.equals(argAttributeValue)) {
    ??????? childElement = localChildElement;
    ??????? break;
    ????? }
    ??? }

    ??? return childElement;
    ? }

    ? //***************************************************************************
    ? /**
    ?? * 指定した要素の內(nèi)容を取得します。
    ?? * @param? argElement 內(nèi)容を取得したい要素
    ?? * @return 內(nèi)容
    ?? */
    ? //***************************************************************************
    ? public static String getElementContents(Element argElement) {
    ??? if(argElement != null) {
    ????? Text text = (Text)argElement.getFirstChild();
    ????? if(text == null) {
    ??????? return null;
    ????? }
    ????? return text.getNodeValue();
    ??? } else {
    ????? return null;
    ??? }
    ? }

    ? //***************************************************************************
    ? /**
    ?? * 指定した親要素の中で最初の子要素の內(nèi)容を取得します。
    ?? * @param? argParentElement 親要素
    ?? * @param? argChildElementName? 內(nèi)容を取得したい子要素名
    ?? * @return 內(nèi)容
    ?? */
    ? //***************************************************************************
    ? public static String getChildElementContents(Element argParentElement,
    ?????????????????????????????????????????????? String argChildElementName) {

    ??? Element childElement = getChildElement(argParentElement,
    ?????????????????????????????????????????? argChildElementName);
    ??? return getElementContents(childElement);
    ? }

    ? //***************************************************************************
    ? /**
    ?? * 指定した親要素の中で指定する屬性の値が設(shè)定されている子要素の內(nèi)容を取得します。
    ?? * @param? argParentElement??? 親要素
    ?? * @param? argChildElementName 內(nèi)容を取得したい子要素名
    ?? * @param? argAttributeName??? 屬性名
    ?? * @param? argAttributeValue?? 屬性の値
    ?? * @return 內(nèi)容
    ?? */
    ? //***************************************************************************
    ? public static String getChildElementContents(Element argParentElement,
    ?????????????????????????????????????????????? String argChildElementName,
    ?????????????????????????????????????????????? String argAttributeName,
    ?????????????????????????????????????????????? String argAttributeValue) {

    ??? Element childElement = getChildElement(argParentElement,
    ?????????????????????????????????????????? argChildElementName,
    ?????????????????????????????????????????? argAttributeName,
    ?????????????????????????????????????????? argAttributeValue);
    ??? return getElementContents(childElement);
    ? }

    ? //***************************************************************************
    ? /**
    ?? * 指定した親要素の中で最初の子要素の屬性の値を取得します。
    ?? * @param? argParentElement??? 親要素
    ?? * @param? argChildElementName 子要素名
    ?? * @param? argAttributeName??? 屬性名
    ?? * @return 屬性の値
    ?? */
    ? //***************************************************************************
    ? public static String getAttributeValue(Element argParentElement,
    ???????????????????????????????????????? String argChildElementName,
    ???????????????????????????????????????? String argAttributeName) {
    ??? return getAttributeValue(argParentElement, argChildElementName, 0, argAttributeName);
    ? }

    ? //***************************************************************************
    ? /**
    ?? * 指定した親要素の中で指定した順番の子要素の屬性の値を取得します。
    ?? * @param? argParentElement?????? 親要素
    ?? * @param? argChildElementName??? 子要素名
    ?? * @param? argSpecificationNumber 順番
    ?? * @param? argAttributeName?????? 屬性名
    ?? * @return 屬性の値
    ?? */
    ? //***************************************************************************
    ? public static String getAttributeValue(Element argParentElement,
    ???????????????????????????????????????? String argChildElementName,
    ???????????????????????????????????????? int argSpecificationNumber,
    ???????????????????????????????????????? String argAttributeName) {
    ??? Element childElement = getChildElement(argParentElement,
    ?????????????????????????????????????????? argChildElementName,
    ?????????????????????????????????????????? argSpecificationNumber);
    ??? return childElement.getAttribute(argAttributeName);
    ? }
    }

    posted on 2006-03-20 15:57 天外飛仙 閱讀(410) 評論(0)  編輯  收藏 所屬分類: XML
    主站蜘蛛池模板: 久久国产精品免费| 亚洲AV无码成人精品区在线观看| 99精品热线在线观看免费视频| 美女裸体无遮挡免费视频网站| 亚洲人成日本在线观看| 亚洲爆乳无码一区二区三区| 国产一级理论免费版| 青青草免费在线视频| 91精品视频在线免费观看| 国产视频精品免费视频| 精品久久亚洲一级α| 国产日本亚洲一区二区三区| 亚洲国产精品久久久久网站| 亚洲综合伊人久久大杳蕉| 免费国产高清视频| 免费特级黄毛片在线成人观看| 57pao国产成永久免费视频| 国内精品久久久久影院免费 | 国产午夜无码精品免费看| 男女污污污超污视频免费在线看 | 免费国产高清视频| 国产资源免费观看| 国产区卡一卡二卡三乱码免费| 18禁无遮挡无码网站免费| 成人无遮挡裸免费视频在线观看| 18禁止看的免费污网站| 91精品免费高清在线| 99久久综合精品免费| 中文字幕免费视频一| 桃子视频在线观看高清免费视频| 好久久免费视频高清| 日韩视频免费在线观看| 久久国产免费一区二区三区| 久久精品一本到99热免费| 一级毛片不卡片免费观看| 久久国产高潮流白浆免费观看| 97在线视频免费播放| 99久久久精品免费观看国产| 免费a级毛片高清视频不卡 | 亚洲欧洲日韩国产| 亚洲AV成人无码天堂|