1、 KSKSKSKSKSKSKSK KSKSKS KSKSK KSKS KSK KS KS X 6047 5 (DOM) 2 KS X 6047 5:2011 2011 12 30 http:/www.kats.go.krKS X 6047 5:2011 :e- ( ) ( ) () () ( ) : () () DRM ( ) KS X 6047 5:2011 : (http:/www.standard.go.kr) : :2011 12 30 2011-0689 : e- : ( 02-509-7262) (http:/www.kats.go.kr). 10 5 , . KS X 6047
2、5:2011 i ii iii 1 1 2 1 3 .1 3.1 .1 3.2 11 4 .19 4.1 .19 4.2 20 4.3 Range .22 4.4 Range .22 4.5 Range .23 4.6 Range .24 4.7 (contents) 25 4.8 25 4.9 26 4.10 26 4.11 27 4.12 Range .27 4.13 Range .29 A( ) IDL 39 A.1 .39 A.2 .41 B( ) 44 B.1 Document Object Model Traversal.44 B.2 .46 C( ) ECMAScripts .4
3、9 C.1 .49 C.2 Document Model Range.51 KS X 6047 5:2011 .55 KS X 6047 5:2011 ii . , , . , , . DOM . DOM XML HTML programmatic interface , . DOM Level 2 . DOM Level 2 Core DOM Level 2 Views DOM Level 2 Events DOM Level 2 Style DOM Level 2 Traversal and Range DOM Level 2 HTML DOM Level 2 Traversal and
4、Range . KS X 6047 5:2011 iii World Wide Web Consortium(W3C) 2000 Document Object Model(DOM) Level 2 Traversal and Range Specificaton 1.0 , . DOM Level 2 Traversal and Range (Traversal) . TreeWalker, Node , NodeFilter API , XML DOM DOM . KS X 6047 5:2011 (DOM) 2 Document Object Model(DOM) level 2 tra
5、versal and range 1 DOM 2 . 2 . . 3 3.1 DOM 2 (Traversal) . TreeWalker, Node , NodeFilter . . DOM DOMImplementation “Traversal” “2.0” hasFeature(feature, version) . , DOM 2 Core DOM 2 Core “Core” . DOM 2 Core DOM 2 Core . Node s TreeWalkersTreeWalkers . Node s , . , ( ) , . , TreeWalker . TreeWalker
6、, Node s . Node s TreeWalkersTreeWalkers . . TreeWalker , NodeFilter . , . KS X 6047 5:2011 2 Node s TreeWalkersTreeWalkers . , . . Node s . TreeWalkers , . . 3.1.1 NodeIterators Node . DOM . , nextnode() . . Node , . , nextNode() null . Node DocumentTraversal createNode . Node . OR . . . NodeIterat
7、or iter= (DocumentTraversal)document). createNodeIterator( root, NodeFilter.SHOW_ELEMENT, null); while (Node n = iter.nextNode() printMe(n); 3.1.1.1 NodeIterators . Iterator , , . Iterator , . Iterator , * . A B C D E F G H I nextNode() . , , nextNode() “A” . A * B C D E F G H I Node s . , , . . pre
8、viousNode() . , A B Node s A . KS X 6047 5:2011 3 A B C D E F G H I nextNode() previousNode() , null . Node . A B C D E F G H I 3.1.1.2 . Node . , Node detach() . , . . , Node . , , . . A B C D * E F G H I , E . . A B C D * F G H I , Node D F F . A B C D * X F G H I . I X . A B C D * I X F G H , . N
9、ode nextnode() , . D . A B C D * F G H I Node , C . A B C * F G H I Node previousNode() , . E . KS X 6047 5:2011 4 A B C D * E F G H I Node , F . A B C D * F G H I , . D . A B C D * F G H I C . A B C * F G H I D , . C . A B * C , Node , C . previousnode() . , . A B * Node , . , C D, E, F C . A B C D
10、 * E F G H I D . A B * G H I D , Node . 3.1.1.3 , Node . whatToShow , nextnode() “ ” . NodeFilter , . , . , null . . previousNode() . KS X 6047 5:2011 5 , . , . A B * c d E F G Nextnode() E . A B c d E * F G , . E . A B c d * F G X d . A B c X d * F G previousNode() X . , . E , d B previousNode() X
11、. 3.1.2 NodeFilters NodeFilters . , . NodeFilter Node TreeWalker . , . NodeFilters . Node . DOM . , NodeFilters . . , TreeWalkers TreeWalkers TreeWalkers . NodeFilter ( , ) , . , FILTER_SHOW FILTER_SKIP TreeWalker , . NodeFilters . 3.1.2.1 NodeFilters NodeFilter acceptNode() , Node TreeWalker NodeKS
12、 X 6047 5:2011 6 . acceptNode() Node . acceptNode() FILTER_ ACCEPT Node . FILTER_SKIP Node Node . FILTER_REJECT Node . , FILTER_REJECT FILTER_SKIP Node s . HTML anchors . HTML HTEF NAME A . anchor JAVA NodeFilter . class NamedAnchorFilter implements NodeFilter short acceptNode(Node n) if (n.getNodeT
13、ype()=Node.ELEMENT_NODE) Element e = (Element)n; if (! e.getNodeName().equals(“A“) return FILTER_SKIP; if (e.getAttributeNode(“NAME“) != null) return FILTER_ACCEPT; return FILTER_SKIP; NodeFilter Node s , FILTER_SKIP FILTER_REJECT , . TreeWalker , FILTER_REJECT anchor ( ) , anchor anchor . FILTER_SK
14、IP . Node TreeWalker . , NodeFilter Node . NamedAnchorFilter myFilter = new NamedAnchorFilter(); NodeIterator iter= (DocumentTraversal)document).createNode( node, NodeFilter.SHOW_ELEMENT, myFilter); NodeFilter nodeType , SHOW_ELEMENT . , whatToShow SHOW_ELEMENT . nodeType , Elements, ATTRs, Processi
15、ngInstructions whatToShow . 3.1.2.2 NodeFilters NodeFilter . KS X 6047 5:2011 7 DOM . TreeWalker Node , . NodeFilter . Node .nextNode() Node .previousNode() TreeWalker .firstChild() TreeWalker .lastChild() TreeWalker .nextSibling() TreeWalker .previousSibling() TreeWalker .nextNode() TreeWalker .pre
16、viousNode() TreeWalker .parentNode() 3.1.2.3 NodeFilters NodeFilters . DOM . . , NodeFilter , Node TreeWalker . , NodeFilters . . 3.1.2.4 NodeFilters whatToShow Node TreeWalker whatToShow . whatToShow NodeFilter . FILTER_SKIP . . , skipNodeFilter . whatToShow SHOW_ALL , nodeType . 3.1.3 TreeWalker T
17、reeWalker Node . TreeWalker . , TreeWalker . TreeWalker . , , . processMe(Node n) nodeStartActions(n); for (Node child=n.firstChild(); KS X 6047 5:2011 8 child != null; child=child.nextSibling() processMe(child); nodeEndActions(n); TreeWalker , . TreeWalker . currentNode / TreeWalker . TreeWalker . processMe(TreeWalker tw) Node n = tw.getCurrentNode(); nodeStartActions(tw); for (Node child=tw.firstChild(); child!=null; child=tw.nextSibling() processMe(tw); tw.setCurrentNode(n); nodeEndActions(tw); Node TreeWalker TreeWalker . ProcssingInstructions . EntityReference . , NodeFilters . .