ÃÑ ÆäÀÌÁö ¼ö : 3224
![]()
|
Facebook Joinc ±×·ì
Joinc QA »çÀÌÆ®
![]()
Tweet
joinc´Â Firefox¿Í chrome¿¡¼ Å×½ºÆ® Çß½À´Ï´Ù. IE¿¡¼´Â Å×À̺íÀÌ ±úÁö°Å³ª À̹ÌÁö°¡ º¸ÀÌÁö ¾ÊÀ» ¼ö ÀÖ½À´Ï´Ù. ƯÈ÷ ±¸±Û DocsÀ̹ÌÁöÀÇ °æ¿ì ¿¢¹Úó¸®µÉ ¼ö ÀÖ½À´Ï´Ù.
À½.. C¸¦ ÀÌ¿ëÇϰí ÀÖ´Ù¸é, ¾Æ¸¶µµ expat¸¦ ÀÌ¿ëÇØ¼ xml µ¥ÀÌÅ͸¦ ó¸®ÇÏ°Ô µÇ¾úÀ» °ÍÀÌ´Ù.
±×°Ô ¾î¼´Ùº¸´Ï, java¸¦ ÀÌ¿ëÇØ¼ ó¸®ÇØ¾ß ÇÏ´Â Çʿ䰡 »ý°å´Ù. µÎ°¡Áö ¾ð¾î ¸ðµÎ º°·Î Àͼ÷ÇÏÁö ¾Ê´Ù´Â°Ô ¸¾¿¡ °É¸°´Ù.
¿ª½Ã³ª. ÀÏ´Ü ¿ë¾îºÎÅͰ¡ ¹®Á¦´Ù. ¹«½¼ ¿ë¾î°¡ À̸® º¹ÀâÇÏ´Ù³Ä. SAX , (´ëÃæ À̸§¸¸ µé¾îºÃÀ» »ÓÀÎ)DOM, Javax, XSLT.. Á» °³³äµµ ±×´Ú ¿Í ´êÁö°¡ ¾Ê´Â´Ù. expat ó·³ Á» Á÷°üÀûÀ¸·Î - ´Ù¸¥¸»·Î ÀýÂ÷ÁöÇâÀûÀ¸·Î- ½áº¼¸¸ÇѰоø³ª ? ã¾ÆºÃ´õ´Ï JDOMÀ̶ó´Â°Ô ÀÖ°í, »ó´çÈ÷ Á÷°üÀûÀÎ °Í °°¾Æ¼, ÀÌ°É »ç¿ëÇØº¸±â·Î Çß´Ù.
°ü½ÉÀÖ´Â ºÎºÐÀº XML ¹®¼ÆÄ½Ì, Element¿Í Attribute¿Í °ªµéÀÇ Ãß°¡ »èÁ¦¿Í °ü·ÃµÈ °ÍµéÀÌ´Ù. µÎ ºÎºÐÀ¸·Î ³ª´©¾î¼ ÇØ¾ß ÇÒ °Í °°´Ù. JDOM ÆÐŰÁö ¾ò±â
´ÙÇàÈ÷ °ø°³ ÆÐŰÁöÀÌ´Ù. °Ô´Ù°¡ º£Å¸¹öÁ¯ÀÌ ¾Æ´Ñ ¾ÈÁ¤¹öÀü 1.1 - 2008/11/25 ±âÁØ - À̶ó´Â°Ô ¸¾¿¡µç´Ù.
ÆÐŰÁö´Â http://www.jdom.org ¿¡¼ ¾òÀ» ¼ö ÀÖ´Ù. XML ¹®¼ ÆÄ½Ì
´ÙÇེ·´°Ôµµ »ó´çÈ÷ Á÷°üÀûÀÌ´Ù. ÄÚµå´Â °£´ÜÇÏ´Ï ¼³¸í »ý·«. package com.yundream.myparser;
import org.jdom.*;
import org.jdom.input.SAXBuilder;
import java.io.IOException;
import java.util.*;
public class jdomParser {
public static void main(String[] args) {
SAXBuilder builder = new SAXBuilder();
String schemType = "";
try {
Document doc = builder.build("entry.xml");
Element root = doc.getRootElement();
System.out.println("Root Node is "+root.getName());
List sqlElement=root.getChildren();
Iterator it = sqlElement.iterator();
while(it.hasNext())
{
Element e = (Element)it.next();
if (e.getName().equals("category"))
{
if (e.getAttribute("schme")!=null)
{
schemType = e.getAttribute("type").getValue();
}
else
{
System.out.println(schemType+" is "+
e.getAttribute(schemType).getValue());
}
}
//System.out.println("Element Name "+e.getName());
}
}
catch(JDOMException e)
{
System.out.println("not well-formed data");
}
catch(IOException e)
{
System.out.println(e);
}
}
}
¾Æ·¡ÀÇ µ¥ÀÌÅ͸¦ Å×½ºÆ® Çß´Ù. tag Á¤º¸¸¦ Àоî¿À°Ô µÉ °ÍÀÌ´Ù.<?xml version="1.0" encoding="UTF-8"?>
<feed>
<entry>
<category schme="type" type="tag" />
<category tag="apple" />
<category tag="computer" />
<category tag="Steven Jobs" />
<author>
<name>yundream</name>
<email>yundream@gmail.com</email>
</author>
</entry>
</feed>
À§ÄÚµå´Â ±×³É µ¹¾Æ°¡´Â ÄÚµå´Ù. node¸íÀ» ÀÔ·ÂÇϸé, ÇØ´ç nodeÀÇ Element¸¦ Àоî¿Àµµ·Ï Çϸé Á»´õ ¹ü¿ëÀûÀ¸·Î »ç¿ëÇÒ ¼ö ÀÖÀ» °Å¶ó »ý°¢µÈ´Ù. ÀÌ ¸Þ¼µå´Â ´ë·« ´ÙÀ½°ú °°Àº ¸ð¾çÀ» ÇÏ¸é µÇÁö ¾ÊÀ»±î. ? nodespace´Â µð·ºÅ丮 Ç¥Çö¹æ½ÄÀ» µû¸£¸é µÉ °ÍÀÌ´Ù. ¿¹¸¦µé¾î À§ÀÇ XML µ¥ÀÌÅÍ¿¡¼ entryÀÇ author node¸¦ ŽÇèÇϱâ À§ÇÑ Element¸¦ ã±æ ¿øÇÑ´Ù¸é "entry/author" ÇÏ¸é µÉ °ÍÀÌ´Ù.
´ÙÀ½Àº Àç±ÍÈ£Ãâ ¸Þ¼µåÀÌ´Ù. static Element getElement(Element node, String namespace) { String nodeList[] = namespace.split("/",2); List ElementList=node.getChildren(); Iterator it = ElementList.iterator(); Element rtvEle = null; while(it.hasNext()) { Element e = (Element)it.next(); if (e.getName().equals(nodeList[0])) { // ´õÀÌ»ó ŽÇèÇÒ ³ëµå°¡ ¾ø´Ù¸é ¸®ÅÏ if (nodeList.length == 1) { return e; } rtvEle=getElement(e, nodeList[1]); } } return rtvEle; }ÀÌ ¸Þ¼µå´Â ´ÙÀ½°ú °°ÀÌ »ç¿ëÇÒ ¼ö ÀÖ´Ù. Element root = doc.getRootElement();
Element findEle=getElement(root,"entry/author");
List authorInfo=findEle.getChildren();
Iterator it = authorInfo.iterator();
while(it.hasNext())
{
Element e = (Element)it.next();
System.out.println("ReadInfo : "+e.getName()+"::"+e.getValue());
}
¿©±â¿¡ ¸î°¡Áö ¸Þ¼µå¸¦ ´õ Ãß°¡ÇÑ´Ù¸é, ±×·°Àú·° µ¹¾Æ°¡´Â ÆÄ¼¸¦ ¸¸µé ¼ö ÀÖÁö ¾ÊÀ»±î¶õ »ý°¢ÀÌ µç´Ù. ¿¹ÄÁµ¥..
|
|
|
EmailÀ» ±âÀÔÇϸé, ´ñ±ÛÀÌ ¸ÞÀÏ·Î Àü´ÞµË´Ï´Ù. |
|