XPath API HOME http xml apache orgxalanj API

  • Slides: 7
Download presentation

XPath. API ± ± ± HOME : http: //xml. apache. org/xalan-j/ API : http:

XPath. API ± ± ± HOME : http: //xml. apache. org/xalan-j/ API : http: //xml. apache. org/xalanj/apidocs/ Lib. Name : xalan. jar

XPath. API를 사용한 예제 1 import java. io. IOException; import org. apache. xpath. XPath.

XPath. API를 사용한 예제 1 import java. io. IOException; import org. apache. xpath. XPath. API; import javax. xml. parsers. Document. Builder. Factory; import javax. xml. parsers. Parser. Configuration. Exception; import javax. xml. transform. Transformer. Exception; import org. w 3 c. dom. Document; import org. w 3 c. dom. Node. List; import org. xml. sax. SAXException; public class XPath. Test 1 { private static final String URL = "http: //blogbridge. naver. com/post. XMLList. jsp? blog. Id=kelinkr"; private static final String XPATH = "//item/title/text()| //item/link/text()"; public static void main(String[] args) throws SAXException, IOException, Parser. Configuration. Exception, Transformer. Exception { Document. Builder. Factory factory = Document. Builder. Factory. new. Instance(); Document feed = factory. new. Document. Builder(). parse(URL); Node. List titles = XPath. API. select. Node. List(feed, XPATH); System. out. println("<? xml version="1. 0"? >rn"); System. out. println("<XPath query=""+XPATH+"">rn"); for (int i = 0; i < titles. get. Length(); i+=2) { System. out. println("t<title>"+titles. item(i). get. Node. Value()+ "</title>rn"); System. out. println("t<link>"+titles. item(i+1). get. Node. Value()+ "</link>rn"); } System. out. println("</XPath>rn"); } }

XPath. API를 사용한 예제 2 import java. io. IOException; import org. apache. xpath. XPath.

XPath. API를 사용한 예제 2 import java. io. IOException; import org. apache. xpath. XPath. API; import javax. xml. parsers. Document. Builder. Factory; import javax. xml. parsers. Parser. Configuration. Exception; import javax. xml. transform. Transformer. Exception; import org. w 3 c. dom. Document; import org. w 3 c. dom. Node. List; import org. xml. sax. SAXException; public class XPath. Test 1 { private static final String URL = "http: //blogbridge. naver. com/post. XMLList. jsp? blog. Id=kelinkr"; private static final String XPATH = "//item/title/text()"; public static void main(String[] args) throws SAXException, IOException, Parser. Configuration. Exception, Transformer. Exception { Document. Builder. Factory factory = Document. Builder. Factory. new. Instance(); Document feed = factory. new. Document. Builder(). parse(URL); Node. List titles = XPath. API. select. Node. List(feed, XPATH); System. out. println("<? xml version="1. 0"? >rn"); System. out. println("<XPath query=""+XPATH+"">rn"); for (int i = 0; i < titles. get. Length(); i++) { System. out. println("t<title>"+titles. item(i). get. Node. Value()+ "</title>rn"); } System. out. println("</XPath>rn"); } }

XPath. API를 사용한 예제 3 public class XPath. Test 1 { private static final

XPath. API를 사용한 예제 3 public class XPath. Test 1 { private static final String URL = "http: //blogbridge. naver. com/post. XMLList. jsp? blog. Id =kelinkr"; private static final String XPATH 1 = "//item"; private static final String XPATH 2 = "child: : title/text()| child: : link/text()"; //private static final String XPATH 2 = "child: : title| child: : link"; public static void main(String[] args) throws SAXException, IOException, Parser. Configuration. Exception, Transformer. Exception { Document. Builder. Factory factory = Document. Builder. Factory. new. Instance(); Document feed = factory. new. Document. Builder(). parse(URL); Node. List items = XPath. API. select. Node. List(feed, XPATH 1); System. out. println("<? xml version="1. 0"? >r"); System. out. println("<XPath query 1=""+XPATH 1+"" query 2=""+XPATH 2+"">"); for (int i = 0; i < items. get. Length(); i++) { Node. List titles = XPath. API. select. Node. List(items. item(i), XPATH 2); System. out. println("t<item>"); for ( int j = 0 ; j < titles. get. Length() ; j += 2 ) { System. out. println("tt<title>"+titles. item(j). get. Node. Value()+ "</title>"); System. out. println("tt<link>"+titles. item(j+1). get. Node. Value()+ "</link>"); /* System. out. println("tt<title>"+titles. item(j). get. Text. Content()+ "</title>"); System. out. println("tt<link>"+titles. item(j+1). get. Text. Content()+ "</link>"); */ } System. out. println("t</item>"); } System. out. println("</XPath>"); } }

XPath. API를 사용한 예제 3 결과 <? xml version="1. 0"? > <XPath query 1="//item"

XPath. API를 사용한 예제 3 결과 <? xml version="1. 0"? > <XPath query 1="//item" query 2="child: : title/text()| child: : link/text()"> 10 <item> <title>부패하지 않는시신. . . </title> <link>http: //blog. naver. com/kelinkr/80008915294</link> </item> <title>다리에 젓꼭지가 자라는 남자. . </title> <link>http: //blog. naver. com/kelinkr/80008915195</link> </item> <title>연말연시 꼭 이런사람들있다. . ㅋㅋㅋ</title> <link>http: //blog. naver. com/kelinkr/80008914943</link> </item> <title>반짝. . </title> <link>http: //blog. naver. com/kelinkr/80008914897</link> </item> <title>종이돈 접기 ^ㅡㅡ^</title> <link>http: //blog. naver. com/kelinkr/80008872043</link> </item> <title>1년에 자기연봉? 큼 수익을 내었나. . . 제기럴. . . </title> <link>http: //blog. naver. com/kelinkr/80008871822</link> </item> <title>반지의 제왕 성인판[19 금]</title> <link>http: //blog. naver. com/kelinkr/80008788605</link> </item> <title>마시마로의 타이완 상륙</title> <link>http: //blog. naver. com/kelinkr/80008788546</link> </item> <title>35억짜리 CF</title> <link>http: //blog. naver. com/kelinkr/80008788525</link> </item> <title>면목동 고내기 유괴사건. . </title> <link>http: //blog. naver. com/kelinkr/80008747947</link> </item> </XPath>