'XML'에 해당되는 글 5건

  1. 2016.03.03 [Java] 외부 프라퍼티(XML) 파일 설정 정보 읽기
  2. 2013.04.05 [java] read properties or xml file.
  3. 2010.05.11 XML Parser javascript class v1.0.0
  4. 2009.03.23 XMLRPC
  5. 2007.10.12 The XSLT/JavaScript Interface in Gecko

[Java] 외부 프라퍼티(XML) 파일 설정 정보 읽기

ITWeb/개발일반 2016.03.03 16:30

외부에 존재하는 properties 파일이나 xml 파일에서 설정 정보를 읽고 싶을 경우가 있습니다.

그래서 기록해 봅니다.


import java.io.*;

import java.util.Properties;


Properties properties = new Properties();

InputStreamReader isr = null;


try {

  isr = new InputStreamReader(new FileInputStream("/server/config/config.properties"), "UTF-8");

  properties.load(isr);

} finally {

  if (null != isr) {

    try {

      isr.close();

    } catch (IOException ex) {}

  }

}


System.out.println(properties.getProperty("프라퍼티명"));


xml을 읽고 싶을 경우 

properties.loadFromXML(InputStream in);

을 이용하시면 됩니다.


저작자 표시 비영리 변경 금지
신고
Trackback 0 : Comment 0

[java] read properties or xml file.

ITWeb/개발일반 2013.04.05 10:57

http://javarevisited.blogspot.kr/2012/03/how-to-read-properties-file-in-java-xml.html


[properties file]

jdbc.username=test

jdbc.password=unknown

jdbc.driver=com.mysql.jdbc.Driver


[source code]

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.util.Properties;


public class PropertyFileReader {


    public static void main(String args[]) throws FileNotFoundException, IOException {


        //Reading properties file in Java example

        Properties props = new Properties();

        FileInputStream fis = new FileInputStream("c:/jdbc.properties");

      

        //loading properites from properties file

        props.load(fis);


        //reading proeprty

        String username = props.getProperty("jdbc.username");

        String driver = props.getProperty("jdbc.driver");

        System.out.println("jdbc.username: " + username);

        System.out.println("jdbc.driver: " + driver);


    }

}


[xml file]

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">

   <properties> <entry key="jdbc.username">root</entry>

        <entry key="jdbc.password">mysql</entry>

   </properties>


[source code]

public static void main(String args[]) throws FileNotFoundException, IOException {


        //Reading properties file in Java example

        Properties props = new Properties();

        FileInputStream fis = new FileInputStream("c:/properties.xml");

      

        //loading properites from properties file

        props.loadFromXML(fis);


        //reading proeprty

        String username = props.getProperty("jdbc.username");

        System.out.println("jdbc.username: " + username);

      

}


신고
tags : Property, XML
Trackback 0 : Comment 0

XML Parser javascript class v1.0.0

ITWeb/개발일반 2010.05.11 12:34
XMLHttpRequest 와 더불어 유용할 것 같아서 만들었습니다.
역시 다른데 코드는 제 스타일도 아니고 읽기도 힘들고 그래서.. 후다닥 만들었다는..
recursive call 을 하기는 하지만 나름 쉽게 작성했습니다.
코드 가지고 태클은 금지.. ㅎㅎ



/*
 * XMLParser Control Module
 *
 * @package
 * @path
 * @filename    xmlparser.js
 * @author      
 * @date        2010/05/03
 *
 * Change History
 * Date         Engineer                Type        Description
 * ----------   ------------------      ---------   --------------------
 * 2010/05/03 Henry Jeong  create  initialize
 */
/*
 *
 * XMLParser module object
 *
 */
var JXmlParser = function() {
};
/*
 *
 * xml parser variables
 */
JXmlParser.prototype.vars = {
 parser : null,
 doc : null,
 xmldata : null,
 root : null,
 xml : null
}
JXmlParser.prototype.init = function() {
 if (window.DOMParser) {
  JXmlParser.vars.parser = new DOMParser();
  JXmlParser.vars.doc = JXmlParser.vars.parser.parseFromString(
    JXmlParser.vars.xmldata, "text/xml");
  JXmlParser.vars.root = JXmlParser.vars.doc.childNodes.item(0);
 } else {
  JXmlParser.vars.doc = new ActiveXObject("Microsoft.XMLDOM");
  JXmlParser.vars.doc.async = "false";
  JXmlParser.vars.doc.loadXML(JXmlParser.vars.xmldata);
  JXmlParser.vars.root = JXmlParser.vars.doc.documentElement;
 }
 JXmlParser.vars.xml = new Object();
 JXmlParser.vars.xml["length"] = JXmlParser.vars.root.childNodes.length;
}
JXmlParser.prototype.setXml2Array = function(pobj, node) {
 var len = node.length;
 if (window.DOMParser) {
  for ( var i = 0; i < len; i++) {
   if (node[i].nodeName.charAt(0) == "#") {
    continue;
   }
   pobj[i] = new Object();
   pobj[i][node[i].nodeName] = new Object();
   pobj[i][node[i].nodeName]["value"] = node[i].textContent;
   pobj[i][node[i].nodeName]["length"] = node[i].childNodes.length;
   pobj[i][node[i].nodeName]["attributes"] = new Object();
   if (node[i].attributes && node[i].attributes.length > 0) {
    var loop = node[i].attributes.length;
    for ( var j = 0; j < loop; j++) {
     pobj[i][node[i].nodeName]["attributes"][node[i].attributes[j].nodeName] = node[i].attributes[j].nodeValue;
    }
   }
   if (node[i].childNodes.length > 0) {
    JXmlParser.setXml2Array(pobj[i][node[i].nodeName],
      node[i].childNodes, node[i].childNodes.length);
   }
  }
 } else {
  for ( var i = 0; i < len; i++) {
   if (node[i].nodeName.charAt(0) == "#") {
    continue;
   }
   pobj[i] = new Object();
   pobj[i][node[i].nodeName] = new Object();
   pobj[i][node[i].nodeName]["value"] = node[i].text;
   pobj[i][node[i].nodeName]["length"] = node[i].childNodes.length;
   pobj[i][node[i].nodeName]["attributes"] = new Object();
   if (node[i].attributes && node[i].attributes.length > 0) {
    var loop = node[i].attributes.length;
    for ( var j = 0; j < loop; j++) {
     pobj[i][node[i].nodeName]["attributes"][node[i].attributes[j].nodeName] = node[i].attributes[j].text;
    }
   }
   if (node[i].childNodes.length > 0) {
    JXmlParser.setXml2Array(pobj[i][node[i].nodeName],
      node[i].childNodes, node[i].childNodes.length);
   }
  }
 }
}
JXmlParser = new JXmlParser();
/*
 * <script type="text/javascript"> <!-- var objDivDebug =
 * document.getElementById("divDebug");
 *
function run() {
 JXmlParser.vars.xmldata = "<?xml version='1.0' encoding='UTF-8'?><parser><totalcount type='number'><total>A</total><total>B</total></totalcount><items name='user' type='image'><item><seq>1</seq><id><![CDATA[jjeong****]]></id><originalImage><![CDATA[http://www.naver.com]]></originalImage><viewImage><![CDATA[http://www.naver.com]]></viewImage><thumbImage><![CDATA[http://www.naver.com]]></thumbImage><cheerMessage><![CDATA[한국어 테스트.]]></cheerMessage><register><![CDATA[20100503175621]]></register></item><item><seq>2</seq><id><![CDATA[layd****]]></id><originalImage><![CDATA[http://www.naver.com]]></originalImage><viewImage><![CDATA[http://www.naver.com]]></viewImage><thumbImage><![CDATA[http://www.naver.com]]></thumbImage><cheerMessage><![CDATA[CHEER MESSAGE]]></cheerMessage><register><![CDATA[20100503175621]]></register></item></items></parser>";
 
 JXmlParser.init();
 JXmlParser.setXml2Array(JXmlParser.vars.xml, JXmlParser.vars.root.childNodes); 
 
 objDivDebug.innerHTML += JXmlParser.vars.xml.length +  "<br>";
 objDivDebug.innerHTML += JXmlParser.vars.xml[0]["totalcount"].value +  "<br>";
 objDivDebug.innerHTML += JXmlParser.vars.xml[0]["totalcount"].attributes.type +  "<br>";
 objDivDebug.innerHTML += JXmlParser.vars.xml[0]["totalcount"].length +  "<br>";
 objDivDebug.innerHTML += JXmlParser.vars.xml[0]["totalcount"][0]["total"].value +  "<br>";
 objDivDebug.innerHTML += JXmlParser.vars.xml[0]["totalcount"][0]["total"].length +  "<br>";
 objDivDebug.innerHTML += JXmlParser.vars.xml[0]["totalcount"][1]["total"].value +  "<br>";
 objDivDebug.innerHTML += JXmlParser.vars.xml[0]["totalcount"][1]["total"].length +  "<br>";
 objDivDebug.innerHTML += JXmlParser.vars.xml[1]["items"].value +  "<br>";
 objDivDebug.innerHTML += JXmlParser.vars.xml[1]["items"].attributes.name +  "<br>";
 objDivDebug.innerHTML += JXmlParser.vars.xml[1]["items"].length +  "<br>"; 
 objDivDebug.innerHTML += JXmlParser.vars.xml[1]["items"][0]["item"] .length+  "<br>";
 objDivDebug.innerHTML += JXmlParser.vars.xml[1]["items"][0]["item"][0]["seq"] .value+  "<br>";
 objDivDebug.innerHTML += JXmlParser.vars.xml[1]["items"][0]["item"][1]["id"] .value+  "<br>";
}
 * //--> </script>
 */
*/

신고
Trackback 0 : Comment 0

XMLRPC

스크랩일반 2009.03.23 10:19
http://wiki.kldp.org/wiki.php/DocbookSgml/XML-RPC-HOWTO
신고
tags : RPC, XML, xmlrpc
Trackback 0 : Comment 0

The XSLT/JavaScript Interface in Gecko

ITWeb/개발일반 2007.10.12 15:24
http://developer.mozilla.org/en/docs/The_XSLT/JavaScript_Interface_in_Gecko

  1. Introduction
  2. JavaScript/XSLT Bindings
  3. Basic Example
  4. Setting Parameters
  5. Advanced Example
  6. Interface List
  7. Resources
신고
tags : dom, XML, XSLT
Trackback 0 : Comment 0