입력값을 검사해서 한글이면 따로 조건을 줘야할때 사용하면 좋다.

public static boolean isKorean(String src) {
    String regEx = "[ㄱ-ㅎㅏ-ㅣ가-힣]*";
    return Pattern.matches(regEx, src);
}

Posted by 짱가쟁이
이번 프로젝트는 나름 알아가는 재미가 있는듯. 입력받은 문자열이 초성만 있는지 검사하는 정규식.

public static boolean isChosung(String src) {
       String regEx = "[ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ]*";
    return Pattern.matches(regEx, src);
}


Posted by 짱가쟁이

클래스에 @XmlRootElement annotation을 사용하지 않은 obejct를 마샬링할 때 사용하면 유용할듯.


public String getMarshallingString(Object obj, String uri, String rootElement) throws Exception {
    JAXBContext jaxbContext;
    StringWriter st = new StringWriter();
    try {
        jaxbContext = JAXBContext.newInstance(obj.getClass());
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.marshal(new JAXBElement(
                  new QName("http://map.star", obj.getClass().getSimpleName()), obj.getClass(), obj ), st);

        return XMLPrinter.prettyFormat(st.toString());
    } catch(Exception e) {
        e.printStackTrace();
        throw e;
    }
}

'java > xml' 카테고리의 다른 글

[JAXB] - unmarshalling, marshalling  (0) 2010.06.29
[xml] - xjc.exe 를 사용한 xsd to java class 생성  (0) 2010.06.29
[xml] - xml to xsd  (0) 2010.06.29
Posted by 짱가쟁이