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

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

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

    飛艷小屋

    程序--人生--哲學___________________歡迎艷兒的加入

    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 天外飛仙 閱讀(409) 評論(0)  編輯  收藏 所屬分類: XML
    主站蜘蛛池模板: 精品国产亚洲男女在线线电影 | 无码不卡亚洲成?人片| 亚洲中文字幕日本无线码| 99久久久国产精品免费牛牛四川| 亚洲精品成人片在线观看精品字幕| 国产va免费观看| 亚洲国产精品乱码一区二区| 在线毛片片免费观看| 亚洲国产综合无码一区| 无码国产精品一区二区免费16| 久久精品国产亚洲av成人| 久久精品电影免费动漫| 亚洲性色成人av天堂| 在线免费一区二区| 日韩毛片一区视频免费| 国产自偷亚洲精品页65页| 十八禁在线观看视频播放免费| 国产成人精品日本亚洲| 18pao国产成视频永久免费| 亚洲六月丁香六月婷婷色伊人| 两个人的视频高清在线观看免费 | 国产又粗又猛又爽又黄的免费视频| 亚洲国产一区二区三区在线观看| 亚洲成年看片在线观看| 成人av片无码免费天天看| 精品亚洲aⅴ在线观看| 女人18毛片免费观看| 黄网站色视频免费看无下截 | 69成人免费视频无码专区| 精品国产亚洲AV麻豆| 亚洲中文字幕无码日韩| 最近2019免费中文字幕视频三| 亚洲人成片在线观看| 亚洲国产成人乱码精品女人久久久不卡| 久久国产美女免费观看精品| 亚洲经典在线中文字幕| 四虎影库久免费视频| 久久午夜夜伦鲁鲁片无码免费| 亚洲va久久久久| 亚洲国产精品无码专区| 在线jyzzjyzz免费视频|