主页 > 互联网  > 

DOMandXPATH

DOMandXPATH
DOM

Originally developed for HTML. Supported by most browsers.

Represents the content of the XML or HTML document as a tree structure.

Using DOM, we can easily read and update the contents of the document.

D: Document —> file

O: Object —> tags elements

M: Model —> layout structure

Online DOM viewer:

Live DOM Viewer

XPATH

Allows us to use path expressions to navigate an XML document.

It allow us to select only the nodes we're interested in.

its :

Expression language.

Contains some standard functions.

Non-XML

XPATH works on the following kinds of nodes:

ExpressionDescriptionnodenameSelects all nodes with the name"nodename"/Selects from the root node//Selects nodes in the document from the current node that match the selection no matter where they are.Selects the value of the current node..Selects the parent of the current node@Selects attributes Predicates

similar to filters

They always appear in[]

They appear after the axis and node text

Path ExpressionResult/bookstore/book[1]Selects the first book element that is the child of the bookstore element./bookstore/book[last()]Selects the last book element that is the child of the bookstore element/bookstore/book[last()-1]Selects the last but one book element that is the child of the bookstore element/bookstore/book[position()<3]Selects the first two book elements that are children of the bookstore element//title[@lang]Selects all the title elements that have an attribute named lang//title[@lang='en']Selects all the title elements that have a "lang" attribute with a value of "en"/bookstore/book[price>35.00]Selects all the book elements of the bookstore element that have a price element/bookstore/book[price>35.00]/titleSelects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00 XPATH Axes

an Axes represents a relationship to the current node on the tree.

AxisNameResultancestorSelects all ancestors (parent, grandparent, etc.) of the current nodeancestor-or-selfSelects all ancestors (parent, grandparent, etc.) of the current node and the current node itselfattributeSelects all attributes of the current nodechildSelects all children of the current nodedescendantSelects all descendants (children, grandchildren, etc.) of the current nodedescendant-or-selfSelects all descendants (children, grandchildren, etc.) of the current node and the current node itselffollowingSelects everything in the document after the closing tag of the current nodefollowing-siblingSelects all siblings after the current nodenamespaceSelects all namespace nodes of the current nodeparentSelects the parent of the current nodeprecedingSelects all nodes that appear before the current node in the document, except ancestors, attribute nodes and namespace nodespreceding-siblingSelects all siblings before the current nodeselfSelects the current node
标签:

DOMandXPATH由讯客互联互联网栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“DOMandXPATH