¥Í¥Ã¥È¥ï¡¼¥¯¥×¥í¥°¥é¥ß¥ó¥°ÆÃÏÀ

Size: px
Start display at page:

Download "¥Í¥Ã¥È¥ï¡¼¥¯¥×¥í¥°¥é¥ß¥ó¥°ÆÃÏÀ"

Transcription

1 8 : Web Same Origin Policy : XML :, XML 1 / 31

2 xml.html: XML xpath-test.html: XPATH valid-test.html: XML (IE ) xslt-test.html: JS XSLT xslt-test.xml: xml xslt.xsl: xslt-test.xml xml weather.rb: XML ruby rss.txt RSS (XML ).rdf (LOD ) 2 / 31

3 XML? XML: extensible Markup Language : (extensible ) : CSS : XPath, XPointer : XSLT (MSXML, Xalan) SAX/Java, DOM/Java, DOM/Perl, DOM/JS, DOM/ruby : RSS rss.txt API 3 / 31

4 <?xml version="1.0" encoding="..."?> ; XML <!DOCTYPE...> ; ; 1 ( ) 4 / 31

5 DTD (Document Type Definition) DTD ( ): <!DOCTYPE PUBLIC " " " "> <!DOCTYPE SYSTEM " "> : -//W3//DTD HTML 3.2//EN ( URI): /usr/local/xml/dtds/simple.dtd DTD : <!DOCTYPE [DTD ]> DTD 5 / 31

6 < 1 =" 1 " 2 =" 2 "... >... </ > < 1 =" 1 " 2 =" 2 "... /> " / -, _,. 1 6 / 31

7 < xmlns: ="URI" >... </ > : <myns:booklist xmlns:myns="http://www. "> <myns:book myns:type="magazine"> </myns:book> </myns:booklist> : <booklist xmlns="http://www. "> <book type="magazine"> </book> </booklist> booklist, book, type 7 / 31

8 <!-- --> <!-- --> ("<" ">") <![CDATA[ ]]> ("]]>" ) 8 / 31

9 XML parsefromstring() xml.html 9 / 31

10 XML : DTD: ( ) XML Schema: DTD (?) Relax NG: DTD DTD 10 / 31

11 ( ) DTD <!DOCTYPE booklist [ <!ELEMENT booklist (book+)> <!ELEMENT book (title,author,publisher)> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ATTLIST author role CDATA "writer"> <!ELEMENT publisher (#PCDATA)> ]> test2.xml XML 11 / 31

12 DTD (Document Type Definition) : <!ELEMENT > ANY EMPTY ( ) #PCDATA * +?,, ; ; 1 ; 0 ; 1 ; 0 or 1 ; ; 12 / 31

13 DTD : <!ATTLIST > ( ATTLIST ) ( ) 2 CDATA ; ( ) ; #REQUIRED 13 / 31

14 DTD : <!ENTITY " "> DTD DTD XML & ; DTD (% ) ( ) 14 / 31

15 HTML DTD HTML DTD : IMG : <!--========== Images ==========================--> <!ELEMENT IMG - O EMPTY> <!ATTLIST IMG SRC CDATA #REQUIRED ALT CDATA #IMPLIED ALIGN (top middle bottom) #IMPLIED ISMAP (ISMAP) #IMPLIED %SDAPREF; "<Fig><?SDATrans Img: #AttList>#AttVal(Alt)</Fig>" > HTML 15 / 31

16 XML Validator XML Linux xmllint Internet Explorer XML ( ) validateonparse true valid-test.xml 16 / 31

17 XPath XPath XML XPath 3.0 (Recommendation Apr 2014) XPath 1.0 XML : : : : : : ( : ) ( : <??>) (DTD ) 17 / 31

18 XPath : : / / / :: [ ] : ( ) : : ( ) : 18 / 31

19 : Attribute, Child, Namespace, Parent, Ancestor, Following-Sibling : *, : : =,!= : and, or : (,...) count(), last(), name(), position(),... : ( ) 19 / 31

20 @... * // : id q3 quote text //quote[source] source quote /quote[position()=last()] quote 20 / 31

21 XPath (snapshot) Snapshot: var xpath = "//title"; var nodes = x.evaluate( xpath, // xpath x, // context null, // namespace resolver XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, // result type null); // reuse result obj 2 evaluate 3 xpath HTML null 4 5 XPathResult snapshot ( ) xpath-test.html 21 / 31

22 XPath (iterator) iterator: ite = x.evaluate(..., XPathResult.UNORDERED_NODE_ITERATOR_TYPE,...); while (node = ite.iteratenext()) { // do something with node } 22 / 31

23 CSS (Cascading Style Sheet) <?xml-stylesheet type="text/css" href="mycss.css"?> HTML 23 / 31

24 XSLT (extensible Style Language Transformation) XML XSLT <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output method="html"/>... </xsl:stylesheet> xsl:output "xml", "html", "text" 24 / 31

25 XSLT <xsl:template match="..."> </xsl:template> match... XPath ( ) xsl:value-of 25 / 31

26 XSLT match // <xsl:apply-templates/> ( ) for-each xsl:call-template ( ) xsl:variable XSLT : XSLT xslt-test.xml xslt.xsl JS XSLT 26 / 31

27 JavaScript XSLT stylesheet = XHR ; processor = new XSLTProcessor(); processor.importstylesheet(stylesheet); fragment = processor.transformtofragment(xmlnode, document); // 1 // 2 fragment owner document xslt-test.html 27 / 31

28 SAX 28 / 31

29 DOM W3C DOM Level 3 Core Specification (DOM4 ) DOM,, Java, ECMAScript Document : : createelement Node : : nodename,nodevalue,nodetype,parentnode,childnodes : appendchild,insertbefore NodeList : NamedNodeMap : Element : : tagname : getattribute, getelementsbytagname Attr : Text : 29 / 31

30 XML <?xml version="1.0" encoding="..."?> encoding utf-16, shift_jis XML MIME Content-Type: text/html; charset=iso ( ) xml:lang="en" xml:lang="en-us" 30 / 31

31 Linked Data SPARQL Linked Data, LOD (Linked Open Data) URI HTTP URI RDF: ja.dbpedia.org.rdf SPARQL = Sparql Protocol and RDF Query Language RDF SELECT WHERE SQL SPARQL 31 / 31