Carpe diem  
  Front Page
Notice | Tag | Location | Guestbook | Admin   
 
'Spring Framework'에 해당하는 글(2)
2008/10/28   [JAXB] 주소록 xmlparser 3. xml 쓰기, 읽기
2008/10/28   [JAXB] 주소록 xmlparser 2. xsd 작성, java 파일 생성하기


2008/10/28 11:51 2008/10/28 11:51
[JAXB] 주소록 xmlparser 3. xml 쓰기, 읽기

** 까먹기 전에 정리하자.

프로젝트의 모든 내용을 까발릴 수는 없으니까 요약 정리함.
(Spring FrameWork + Flex 통신 중 사용)

1. 쓰기

/**
  * 참고 코드 : JAXB - 파일 읽기
  * @param input : xml 만들 리스트
  * @param pw: xml 쓸 곳 ( 여기서는 화면에 )
  * @return
  * @throws JAXBException
  */
 public void writeGroupXML(List input, PrintWriter pw) throws JAXBException, FileNotFoundException
 {
  ObjectFactory objFactory = new ObjectFactory();
  AddressBook ad = (AddressBook) objFactory.createAddressBook();
  AddressBook.Groups grps = objFactory.createAddressBookGroups();
 
  List grpList = grps.getGroup();

  for(int i=0; i<input.size(); i++)
  {
   GroupType grp = objFactory.createGroupType();
   GroupVO gv = new GroupVO();
   gv = (GroupVO)input.get(i);
   
   grp.setGroupNm(gv.getGroupNm());
   grp.setGroupSeqNo(gv.getGroupSeqNo());
   grpList.add(grp);
  }
 
  ad.setGroups(grps);
 
  JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
  Marshaller marshaller = jaxbContext.createMarshaller();
  marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
  marshaller.marshal(ad, pw);
 }




2. 읽기

/**
  * 참고 코드 : JAXB - 파일 읽기
  * @param strFile 파일 경로 + 이름까지
  * @return
  * @throws JAXBException
  */
 public List readXMLFile(String strFile) throws JAXBException
 {
  JAXBContext jaxbContext = JAXBContext.newInstance("com.evelyn.msg.xml");
  Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
  AddressBook ad= (AddressBook)unmarshaller.unmarshal(new File(strFile));
   
  AddressBook.Buddies bds = ad.getBuddies();
  List bdt = bds.getBuddy();
 
  for(int i = 0; i < bdt.size(); i++)
  {
   BuddyType bt = (BuddyType)bdt.get(i);
  }
  return bdt;
 }



 /**
  * 참고 코드 : JAXB - XML 문자열 읽기
  * @param strXml XML 문자열
  * @return
  * @throws JAXBException
  */
 public List readXML(String strXml) throws JAXBException
 {
  if(strXml == "")
  {
   logger.info("null string");
   return null;
  }
 
  JAXBContext jaxbContext = JAXBContext.newInstance("com.evelyn.msg.xml");
  Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
  StringBuffer xmlStr = new StringBuffer(strXml);
  AddressBook ad = (AddressBook)unmarshaller.unmarshal(new StreamSource(new StringReader( xmlStr.toString())));
  AddressBook.Buddies bds = ad.getBuddies();
  List bdt = bds.getBuddy();
  return bdt;
 }


크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
Tag : , ,


2008/10/28 11:44 2008/10/28 11:44
[JAXB] 주소록 xmlparser 2. xsd 작성, java 파일 생성하기

** 까먹기 전에 정리하자.

프로젝트의 모든 내용을 까발릴 수는 없으니까 요약 정리함.
(Spring FrameWork + Flex 통신 중 사용)

1. 주소록 xsd 를 만든다.

주소록 - 그룹 - 버디의 구조.

<?xml version="1.0" encoding="EUC-KR"?>
<xs:schema xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" jaxb:version="1.0">
 <xs:element name="AddressBook">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="buddies" minOccurs="0">
     <xs:complexType>
      <xs:sequence>
       <xs:element name="buddy" type="buddyType" maxOccurs="unbounded"/>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
    <xs:element name="groups" minOccurs="0">
     <xs:complexType>
      <xs:sequence>
       <xs:element name="group" type="groupType" maxOccurs="unbounded"/>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
 <xs:complexType name="groupType">
  <xs:sequence>
   <xs:element name="groupSeqNo">
    <xs:simpleType>
     <xs:restriction base="xs:long"/>
    </xs:simpleType>
   </xs:element>
   <xs:element name="groupNm">
    <xs:simpleType>
     <xs:restriction base="xs:string"/>
    </xs:simpleType>
   </xs:element>
  </xs:sequence>
 </xs:complexType>
 <xs:complexType name="buddyType">
  <xs:sequence>
   <xs:element name="buddyNm">
    <xs:simpleType>
     <xs:restriction base="xs:string">
      <xs:minLength value="1"/>
     </xs:restriction>
    </xs:simpleType>
   </xs:element>
   <xs:element name="hpNo">
    <xs:simpleType>
     <xs:restriction base="xs:string">
      <xs:pattern value="[0-9\-]*"/>
     </xs:restriction>
    </xs:simpleType>
   </xs:element>
   <xs:element name="emailId" minOccurs="0">
    <xs:simpleType>
     <xs:restriction base="xs:string"/>
    </xs:simpleType>
   </xs:element>
  </xs:sequence>
 </xs:complexType>
</xs:schema>


2. 컴파일 한다.

컴파일 방법 참고 -> http://www.evelyn.pe.kr/kor/122

3. 다음의 파일이 생긴다.

AddressBook.java
BuddyType.java
GroupType.java
ObjectFactory.java

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
Tag : ,


BLOG main image
Passionate, Crazy
 Notice
 Category
전체 (71)
여행 (22)
취미/여가 (8)
지식/공부 (28)
독서/감상 (6)
 TAGS
Dashboard iphone IBM 시먼딩 멀티캠퍼스 ASP.NET 휴식 댄스 Mac 금강산 쿼리문 갤러리 Oracle 용어사전 무기력 고3 대만 괴물 고양이 미친소 방글라데시 먹거리 아기 만화 jaxb 자바 쭝샤오거리 앨빈 토플러 스타 오라클 911 PHP 이순신 VC++ 배경음악 간사이 이벤트 이타바시혼쵸 팝페라 여름휴가 아이스쇼 태터 한국인 증권 닮은꼴 경제 언론 바탕화면 다이어리 딴수이 101빌딩 하이버네이트 NSString KTX 대만여행정보 홍수 단일연결리스트 Excel 추억 환형연결리스트 대학로 공감툰 일본여행 사전 MS 개발툴 후원 와인 로만자 비트 매니아 학교 태터스킨 O-fone 태그 3D 도쿄 태터툴즈 전시회 날씨 해모수 펀드 지하철 Spring Framework MFC 스위스 구글 더바디샵 핸드메이드 근황보고 제거 엠티 구글애드센스 영어공부 jsxb 영화 Widget
 Calendar
«   2012/02   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      
 Recent Entries
[Hibernate] criteria or...
[Hibernate] 중복된 row...
[freemarker] 숫자 콤마 빼기
고베의 일품 야경을 늦게...
간사이 지역 여행 준비하기
object param 값
[FLEX] Renderer를 이용하...
아이폰 SDK - md5
NSString 문자열 길이를 U...
JSP Get 방식 한글 parame... (3)
 Recent Comments
get방식으로 받은 한글이...
데잇 - 2009
당연히 해봤죠 ~ ^^; 여...
euni - 2009
request.setCharacterEnco...
꼼즈 - 2009
궁금하던 정보 잘 얻고 갑...
해피포터 - 2008
나는 언제 성장하는 거냐?
SEAN。 - 2008
받아들이는 관점에 따라...
euni - 2008
성장이 맞는 것 같지만,...
euni - 2008
거럼 뭐가 메카지? ㅋㅋㅋ...
euni - 2008
종합선물세트 아닐까요 ㅎㅎ
ho - 2008
성장만화 아니었습니까?
SEAN。 - 2008
 Recent Trackbacks
 Archive
2011/10
2010/06
2010/03
2009/09
2009/06
 Link Site
소니톤/개발/애니/여행/e-...
지식보다 지혜를...
 Visitor Statistics
Total : 185919
Today : 41
Yesterday : 44
태터툴즈 배너
rss