`
垂直的微笑
  • 浏览: 45442 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

SAX解析XML

    博客分类:
  • JAVA
 
阅读更多

// イニシャルコンテキスト取得
		Context ctx = (Context) new InitialContext();
		// 環境変数取得用コンテキスト取得
		Context envCtx = (Context) ctx.lookup("java:comp/env");
		// 設定ファイル名取得
		String propertyFile = (String) envCtx.lookup("property_file_name");
		// ジャンルファイルのパスを取得する
		String xmlFileDir = propertyFile.substring(0, propertyFile.lastIndexOf("/") + 1);
		String xmlFileStr = xmlFileDir + XML_FILE_NAME;
		File xmlFile = new File(xmlFileStr);
		if (null == xmlFile || !xmlFile.exists()) {
			Log.out(Log.DEBUG, "[PrefParser] XML file doesn't exist");
			return;
		}

		InputSource input = new InputSource(new BufferedInputStream(new FileInputStream(xmlFile)));
		input.setEncoding(XML_FILE_ENCODE);
		
		XMLReader reader = XMLReaderFactory.createXMLReader();
		reader.setContentHandler(Handler.getInstance());
		reader.parse(input);
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics