XPath
<XML_XPath> Bài 8: Một số cú pháp cơ bản của XPath.
1.Select node
Các bạn có thể đọc tại http://www.w3schools.com/xsl/xpath_operators.asp.
3. Ví dụ: <nguồn https://www.w3.org>
- paraselects theparaelement children of the context node- *selects all element children of the context node- text()selects all text node children of the context node- @nameselects thenameattribute of the context node- @*selects all the attributes of the context node- para[1]selects the firstparachild of the context node- para[fn:last()]selects the lastparachild of the context node- */paraselects allparagrandchildren of the context node- /book/chapter[5]/section[2]selects the secondsectionof the fifthchapterof thebookwhose parent is the document node that contains the context node- chapter//paraselects theparaelement descendants of thechapterelement children of the context node- //paraselects all theparadescendants of the root document node and thus selects allparaelements in the same document as the context node- //@versionselects all theversionattribute nodes that are in the same document as the context node- //list/memberselects all thememberelements in the same document as the context node that have alistparent- .//paraselects theparaelement descendants of the context node- ..selects the parent of the context node- ../@langselects thelangattribute of the parent of the context node- para[@type="warning"]selects allparachildren of the context node that have atypeattribute with valuewarning- para[@type="warning"][5]selects the fifthparachild of the context node that has atypeattribute with valuewarning- para[5][@type="warning"]selects the fifthparachild of the context node if that child has atypeattribute with valuewarning- chapter[title="Introduction"]selects thechapterchildren of the context node that have one or moretitlechildren whose typed value is equal to the stringIntroduction- chapter[title]selects thechapterchildren of the context node that have one or moretitlechildren- employee[@secretary and @assistant]selects all theemployeechildren of the context node that have both asecretaryattribute and anassistantattribute- book/(chapter|appendix)/sectionselects everysectionelement that has a parent that is either achapteror anappendixelement, that in turn is a child of abookelement that is a child of the context node.- - If
Eis any expression that returns a sequence of nodes, then the expressionE/.returns the same nodes in document order, with duplicates eliminated based on node identity.
4. Các Hàm <Functions>
4.1 Boolean functions ( T - F )
• Boolean boolean(arg) //returns false if object equal to zero/NaN/empty
• Boolean false() //returns the Boolean value false
• Boolean lang(string arg) //to check language which is used in context node
• Boolean not(arg) //
• Boolean true() // returns the Boolean value true
4.2 Node-set Functions
• number count(node-set arg) //returns the number of nodes
• node-set id(string arg) //returns a node-set
• last() // returns a value equal to the context size
• string local-name(optional node-set arg) //returns local name(context node)
• string name(optional node-set arg) //returns the nam of node in QName format
• string namespace-uri(optional node-set arg) //returns namespace-uri of node-set
• Number position() //returns value equal to the context position
4.3 Numeric Functions
• number ceiling( number arg) //returns the smallest integer greater than this
• number floor(number arg) //returns the largest integer that is lower than this
• number number(arg) //to convert string, Boolean, node-set to number //returns NaN if can not convert
• number round(number arg) //returns the integer that is closest to the number arg
• number sum(node-set arg) // return sum of node in node-set // return NaN if node can’t converted to number
4.4 String Functions
• string concat(string arg1, arg2) //returns the concatenation of those strings
• Boolean contains(string arg1, arg2) //returns true if arg1 contains arg2
• string normalize-space(string arg1) //=trim & replace whitespace=single space
• Boolean start-with(string arg1, arg2) //returns true if arg1 starts with arg2
• string string(arg) //to convert Boolean, node-set, number to string
• number string-length(string arg) //returns the length of the string arg
• string substring(string arg1, number arg2, optional number arg3) //return substring of arg1
• string substring-before(string arg1, arg2) //
• string substring-after(string arg1, arg2) //
• string translate(string arg1, arg2, arg 3) //
Chúc các bạn thành công!


























ahihi thanks
ReplyDelete