Java XPath API (한글)

Similar documents
02 C h a p t e r Java

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

rmi_박준용_final.PDF

07 자바의 다양한 클래스.key

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

비긴쿡-자바 00앞부속

12-file.key

신림프로그래머_클린코드.key

ch09

* Factory class for query and DML clause creation * tiwe * */ public class JPAQueryFactory implements JPQLQueryFactory private f

PowerPoint 프레젠테이션

05-class.key

교육자료

09-interface.key

03장.스택.key

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

DocsPin_Korean.pages

JMF3_심빈구.PDF

1

01-OOPConcepts(2).PDF

5장.key

JMF2_심빈구.PDF

자바GUI실전프로그래밍2_장대원.PDF

MasoJava4_Dongbin.PDF

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

목차 INDEX JSON? - JSON 개요 - JSONObject - JSONArray 서울시공공데이터 API 살펴보기 - 요청인자살펴보기 - Result Code - 출력값 HttpClient - HttpHelper 클래스작성 - JSONParser 클래스작성 공공

쉽게 풀어쓴 C 프로그래밊

untitled

Interstage5 SOAP서비스 설정 가이드

Cluster management software

04장

mytalk

PowerPoint 프레젠테이션

Java

Spring Boot/JDBC JdbcTemplate/CRUD 예제

Java ...

자바 프로그래밍

API STORE 키발급및 API 사용가이드 Document Information 문서명 : API STORE 언어별 Client 사용가이드작성자 : 작성일 : 업무영역 : 버전 : 1 st Draft. 서브시스템 : 문서번호 : 단계 : Docum

@OneToOne(cascade = = "addr_id") private Addr addr; public Emp(String ename, Addr addr) { this.ename = ename; this.a

Microsoft PowerPoint - Supplement-03-TCP Programming.ppt [호환 모드]

FileMaker ODBC and JDBC Guide

교육2 ? 그림

03-JAVA Syntax(2).PDF

I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

Microsoft PowerPoint 자바-기본문법(Ch2).pptx

FileMaker ODBC and JDBC Guide

JUNIT 실습및발표

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

초보자를 위한 C# 21일 완성

PowerPoint Presentation

2017 년 6 월한국소프트웨어감정평가학회논문지제 13 권제 1 호 Abstract

Contents Contents 2 1 Abstract 3 2 Infer Checkers Eradicate Infer....

Microsoft PowerPoint - 04-UDP Programming.ppt

( )부록

2파트-07

untitled

Microsoft PowerPoint - ch10 - 이진트리, AVL 트리, 트리 응용 pm0600

thesis

FileMaker 15 ODBC 및 JDBC 설명서

Spring Data JPA Many To Many 양방향 관계 예제

4장.문장

Microsoft PowerPoint - 03-TCP Programming.ppt

PowerPoint Presentation

OOP 소개

어댑터뷰

Data Provisioning Services for mobile clients

example code are examined in this stage The low pressure pressurizer reactor trip module of the Plant Protection System was programmed as subject for


기술문서 작성 XXE Attacks 작성자 : 인천대학교 OneScore 김영성 I. 소개 2 II. 본문 2 가. XML external entities 2 나. XXE Attack 3 다. 점검방법 3 라.

PowerPoint Presentation

13ÀåÃß°¡ºÐ

(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI= ; // PI 이름으로 로초기화된정적상수 public

Javascript.pages

Something that can be seen, touched or otherwise sensed

10장.key

국어부록표지

_....

歯k"

03장

chap01_time_complexity.key

class Sale void makelineitem(productspecification* spec, int qty) SalesLineItem* sl = new SalesLineItem(spec, qty); ; 2. 아래의액티비티다이어그램을보고 Java 또는 C ++,

chap10.PDF

FileMaker ODBC 및 JDBC 가이드

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

Microsoft PowerPoint - lec2.ppt

K&R2 Reference Manual 번역본

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

PowerPoint 프레젠테이션

A Tour of Java IV

슬라이드 1

5.스택(강의자료).key

XML DTD

PowerPoint Presentation

NoSQL

Microsoft PowerPoint - RMI.ppt

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Cluster management software

Transcription:

XML : Elliotte Rusty Harold, Adjunct Professor, Polytechnic University 2006 9 04 2006 10 17 문서옵션 제안및의견 XPath Document Object Model (DOM). XML XPath. Java 5 XPath XML - javax.xml.xpath.,? "?"? ".... 4. 5..."? ".".., "Find a copy of Cryptonomicon". "Find all the books by Neal Stephenson". XPath, Structured Query Language (SQL). Object Query Language (OQL) XQuery. XML XPath., Neal Stephenson XPath. //book[author="neal Stephenson"]/title DOM Listing 1 : Listing 1. Neal Stephenson DOM http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (1 / 17) [2008-03-14 8:47:46]

ArrayList result = new ArrayList(); NodeList books = doc.getelementsbytagname("book"); for (int i = 0; i < books.getlength(); i++) { Element book = (Element) books.item(i); NodeList authors = book.getelementsbytagname("author"); boolean stephenson = false; for (int j = 0; j < authors.getlength(); j++) { Element author = (Element) authors.item(j); NodeList children = author.getchildnodes(); StringBuffer sb = new StringBuffer(); for (int k = 0; k < children.getlength(); k++) { Node child = children.item(k); // really should to do this recursively if (child.getnodetype() == Node.TEXT_NODE) { sb.append(child.getnodevalue()); if (sb.tostring().equals("neal Stephenson")) { stephenson = true; break; http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (2 / 17) [2008-03-14 8:47:46]

if (stephenson) { NodeList titles = book.getelementsbytagname("title"); for (int j = 0; j < titles.getlength(); j++) { result.add(titles.item(j)); Listing 1 DOM XPath.,,?. XPath. XPath. XPath.., XPath International Standard Book Number (ISBN)., XPath. XPath., XPath (API) XPath. Xalan API, Saxon API, API.. Java 5 javax.xml.xpath XPath. XML Processing (JAXP) 1.3 API Java 1.3., Xalan 2.7 Saxon 8.. Neal Stephenson., Listing 2 : http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (3 / 17) [2008-03-14 8:47:46]

Listing 2. XML <inventory> <book year="2000"> <title>snow Crash</title> <author>neal Stephenson</author> <publisher>spectra</publisher> <isbn>0553380958</isbn> <price>14.95</price> </book> <book year="2005"> <title>burning Tower</title> <author>larry Niven</author> <author>jerry Pournelle</author> <publisher>pocket</publisher> <isbn>0743416910</isbn> <price>5.99</price> <book> <book year="1995"> <title>zodiac</title> <author>neal Stephenson<author> http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (4 / 17) [2008-03-14 8:47:46]

<publisher>spectra</publisher> <isbn>0553573862</isbn> <price>7.50</price> <book> <!-- more books... --> </inventory> XPath : //book[author="neal Stephenson"].,. //book[author="neal Stephenson"]/title. title.. : //book [author="neal Stephenson"]/title/ text(). XPathFactory. API DOM, JDOM, XOM. Uniform Resource Identifier (URI) XPathFactory. newinstance()., http://xom.nu/ XOM., API DOM.,,., DOM Document. books.xml. Document : Listing 3. JAXP DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setnamespaceaware(true); // never forget this! DocumentBuilder builder = factory.newdocumentbuilder(); Document doc = builder.parse("books.xml"); http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (5 / 17) [2008-03-14 8:47:46]

, JAXP DOM.. XPathFactory : XPathFactory factory = XPathFactory.newInstance(); XPath : XPath xpath = factory.newxpath(); XPath XPath : PathExpression expr = xpath.compile("//book[author='neal Stephenson']/title/text()"); XPath Immediate evaluation. XPath. XPath. evaluate().. node-set :. Object result = expr.evaluate(doc, XPathConstants.NODESET); DOM NodeList : NodeList nodes = (NodeList) result; for (int i = 0; i < nodes.getlength(); i++) { System.out.println(nodes.item(i).getNodeValue()); Listing 4. throws. Listing 4. XPath XML http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (6 / 17) [2008-03-14 8:47:46]

import java.io.ioexception; import org.w3c.dom.*; import org.xml.sax.saxexception; import javax.xml.parsers.*; import javax.xml.xpath.*; public class XPathExample { public static void main(string[] args) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { DocumentBuilderFactory domfactory = DocumentBuilderFactory.newInstance(); domfactory.setnamespaceaware(true); // never forget this! DocumentBuilder builder = domfactory.newdocumentbuilder(); Document doc = builder.parse("books.xml"); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newxpath(); XPathExpression expr = xpath.compile("//book[author='neal Stephenson']/title/text()"); http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (7 / 17) [2008-03-14 8:47:46]

Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; for (int i = 0; i < nodes.getlength(); i++) { System.out.println(nodes.item(i).getNodeValue()); XPath XPath,.. XPath. XPath 1.0 : node-set number boolean string,. XPath, node-set.., XPath count (//book). XPath count(//book[@author="neal Stephenson"]) > 10 : Neal Stephenson 10 true 10 false. evaluate() Object. XPath,. XPath, java.lang.double. java.lang.string. java.lang.boolean. node-set org.w3c.dom.nodelist. XPath. http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (8 / 17) [2008-03-14 8:47:46]

, javax.xml.xpath.xpathconstants XPath 2 :, XPath 1.0 XPathConstants.NODESET. XPath 2 XPathConstants.BOOLEAN XPathConstants.NUMBER. XPath 2 XPathConstants.STRING XPath API XPathConstants.NODE XPathConstants.NODE XPath XPath 2. XPath.. XPath XPathConstants.NODE evaluate(). XPath XPathConstants.NODE evaluate() null. evaluate() XPathException. XML XPath. XPath URI., XML XPath.,., XML. URI. javax.xml.namespace.namespacecontext. http://www.example.com/books Listing 5 : Listing 5. XML http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (9 / 17) [2008-03-14 8:47:46]

<inventory xmlns="http://www.example.com/books"> <book year="2000"> <title>snow Crash</title> <author>neal Stephenson</author> <publisher>spectra</publisher> <isbn>0553380958</isbn> <price>14.95<price> </book> <!-- more books... --> <inventory> Neal Stephenson XPath //pre:book[pre:author="neal Stephenson"]/pre: title/text(). pre http://www.example.com/books URI. NamespaceContext (JDK) JAXP.. Listing 6. xml. Listing 6. http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (10 / 17) [2008-03-14 8:47:46]

import java.util.iterator; import javax.xml.*; import javax.xml.namespace.namespacecontext; public class PersonalNamespaceContext implements NamespaceContext { public String getnamespaceuri(string prefix) { if (prefix == null) throw new NullPointerException("Null prefix"); else if ("pre".equals(prefix)) return "http://www.example.org/books"; else if ("xml".equals(prefix)) return XMLConstants.XML_NS_URI; return XMLConstants.NULL_NS_URI; // This method isn't necessary for XPath processing. public String getprefix(string uri) { throw new UnsupportedOperationException(); // This method isn't necessary for XPath processing either. public Iterator getprefixes(string uri) { throw new UnsupportedOperationException(); http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (11 / 17) [2008-03-14 8:47:46]

. NamespaceContext, XPath.. Listing 7. XPath XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newxpath(); xpath.setnamespacecontext(new PersonalNamespaceContext()); XPathExpression expr = xpath.compile("//pre:book[pre:author='neal Stephenson']/pre:title/text()"); Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; for (int i = 0; i < nodes.getlength(); i++) { System.out.println(nodes.item(i).getNodeValue());, XPath. XPath..,. (XPath.) XPath API javax.xml.xpath.xpathfunction., evaluate : http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (12 / 17) [2008-03-14 8:47:46]

public Object evaluate(list args) throws XPathFunctionException XPath. String Double Boolean Nodelist Node, Listing 8 ISBN Boolean. 9. ( 1 2.) 11. 10 X. Listing 8. ISBN XPath import java.util.list; import javax.xml.xpath.*; import org.w3c.dom.*; public class ISBNValidator implements XPathFunction { // This class could easily be implemented as a Singleton. public Object evaluate(list args) throws XPathFunctionException { if (args.size()!= 1) { throw new XPathFunctionException("Wrong number of arguments to valid-isbn()"); http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (13 / 17) [2008-03-14 8:47:46]

String isbn; Object o = args.get(0); // perform conversions if (o instanceof String) isbn = (String) args.get(0); else if (o instanceof Boolean) isbn = o.tostring(); else if (o instanceof Double) isbn = o.tostring(); else if (o instanceof NodeList) { NodeList list = (NodeList) o; Node node = list.item(0); // gettextcontent is available in Java 5 and DOM 3. // In Java 1.4 and DOM 2, you'd need to recursively // accumulate the content. isbn= node.gettextcontent(); else { throw new XPathFunctionException("Could not convert argument type"); char[] data = isbn.tochararray(); if (data.length!= 10) return Boolean.FALSE; int checksum = 0; for (int i = 0; i < 9; i++) { http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (14 / 17) [2008-03-14 8:47:46]

checksum += (i+1) * (data[i]-'0'); int checkdigit = checksum % 11; if (checkdigit + '0' == data[9] (data[9] == 'X' && checkdigit == 10)) { return Boolean.TRUE; return Boolean.FALSE;. XPath javax.xml.xpath.xpathfunctionresolver. Resolver XPath URI. Listing 9 http://www.example.org/books valid-isbn Listing 8., XPath //book[not(pre: valid-isbn(isbn))] ISBM. Listing 9. isbn iimport javax.xml.namespace.qname; import javax.xml.xpath.*; public class ISBNFunctionContext implements XPathFunctionResolver { private static final QName name http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (15 / 17) [2008-03-14 8:47:46]

= new QName("http://www.example.org/books", "valid-isbn"); public XPathFunction resolvefunction(qname name, int arity) { if (name.equals(isbnfunctioncontext.name) && arity == 1) { return new ISBNValidator(); return null; NamespaceResolver.. XPathFunctionResolver, XPathFunction, NamespaceResolver. SQL XPath C. C SQL XPath. XPathFunctionResolver, XPathFunction, NamespaceResolver API. XML javax.xml.xpath java.sql. The Java XPath API "XPath 2.0 " by Benoît Marchal (developerworks korea, 2006 5 ) http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (16 / 17) [2008-03-14 8:47:46]

Working with JAXP namespace contexts XML in a Nutshell (Elliotte Rusty Harold and W. Scott Means, O'Reilly, 2005) IBM XML 1.1 certification XML developerworks technical events and webcasts JAXP Project Xalan 2 SAXON 8 IBM trial software XML developerworks blogs Elliotte Rusty Harold New Orleans. Beth Charm Marjorie Brooklyn Prospect Heights. Polytechnic University. Cafe au Lait, Cafe con Leche XML. Effective XML, Processing XML with Java, Java Network Programming, Java I/O, 2nd edition. XML XOM API, Jaxen XPath Jester. 9 Java at Software Development Best Practices. http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html (17 / 17) [2008-03-14 8:47:46]