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

2 XPathAPI HOME : API : 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 ^ ^ 1 ? [19 ] 35 CF


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

Similar presentations


Ads by Google