Presentation is loading. Please wait.

Presentation is loading. Please wait.

XPathAPI 2005. 01. 05. XPathAPI HOME : API : j/apidocs/ Lib.

Similar presentations


Presentation on theme: "XPathAPI 2005. 01. 05. XPathAPI HOME : API : j/apidocs/ Lib."— Presentation transcript:

1 XPathAPI 2005. 01. 05

2 XPathAPI HOME : http://xml.apache.org/xalan-j/http://xml.apache.org/xalan-j/ API : http://xml.apache.org/xalan- j/apidocs/ Lib. Name : xalan.jar

3 XPathAPI XML

4 XPathAPI 1 import java.io.IOException; import org.apache.xpath.XPathAPI; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class XPathTest1 { private static final String URL = "http://blogbridge.naver.com/post/postXMLList.jsp?blogId=kelinkr"; private static final String XPATH = "//item/title/text()| //item/link/text()"; public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException, TransformerException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document feed = factory.newDocumentBuilder().parse(URL); NodeList titles = XPathAPI.selectNodeList(feed, XPATH); System.out.println(" \r\n"); for (int i = 0; i < titles.getLength(); i+=2) { System.out.println("\t "+titles.item(i).getNodeValue()+ " \r\n"); System.out.println("\t "+titles.item(i+1).getNodeValue()+ " \r\n"); } System.out.println(" \r\n"); }

5 XPathAPI 2 import java.io.IOException; import org.apache.xpath.XPathAPI; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class XPathTest1 { private static final String URL = "http://blogbridge.naver.com/post/postXMLList.jsp?blogId=kelinkr"; private static final String XPATH = "//item/title/text()"; public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException, TransformerException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document feed = factory.newDocumentBuilder().parse(URL); NodeList titles = XPathAPI.selectNodeList(feed, XPATH); System.out.println(" \r\n"); for (int i = 0; i < titles.getLength(); i++) { System.out.println("\t "+titles.item(i).getNodeValue()+ " \r\n"); } System.out.println(" \r\n"); }

6 XPathAPI 3 public class XPathTest1 { private static final String URL = "http://blogbridge.naver.com/post/postXMLList.jsp?blogId=kelinkr"; private static final String XPATH1 = "//item"; private static final String XPATH2 = "child::title/text()| child::link/text()"; //private static final String XPATH2 = "child::title| child::link"; public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException, TransformerException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document feed = factory.newDocumentBuilder().parse(URL); NodeList items = XPathAPI.selectNodeList(feed, XPATH1); System.out.println(" \r"); System.out.println(" "); for (int i = 0; i < items.getLength(); i++) { NodeList titles = XPathAPI.selectNodeList(items.item(i), XPATH2); System.out.println("\t "); for ( int j = 0 ; j < titles.getLength() ; j += 2 ) { System.out.println("\t\t "+titles.item(j).getNodeValue()+ " "); System.out.println("\t\t "+titles.item(j+1).getNodeValue()+ " "); /* System.out.println("\t\t "+titles.item(j).getTextContent()+ " "); System.out.println("\t\t "+titles.item(j+1).getTextContent()+ " "); */ } System.out.println("\t "); } System.out.println(" "); }

7 XPathAPI 3 10... http://blog.naver.com/kelinkr/80008915294.. http://blog.naver.com/kelinkr/80008915195.. http://blog.naver.com/kelinkr/80008914943.. http://blog.naver.com/kelinkr/80008914897 ^ ^ http://blog.naver.com/kelinkr/80008872043 1 ?...... http://blog.naver.com/kelinkr/80008871822 [19 ] http://blog.naver.com/kelinkr/80008788605 http://blog.naver.com/kelinkr/80008788546 35 CF http://blog.naver.com/kelinkr/80008788525.. http://blog.naver.com/kelinkr/80008747947


Download ppt "XPathAPI 2005. 01. 05. XPathAPI HOME : API : j/apidocs/ Lib."

Similar presentations


Ads by Google