Sintaxe de XPath
|
A língua do trajeto de XML usa uma notação declarativa melhor que processual. Cada expressão tornou-se por esta notação descreve os tipos de nós ao fósforo baseado no relacionamento hierárquico entre os nós. Por exemplo, autor da expressão do “os meios livro/” encontram o elemento do autor contido no elemento do livro.
|
Exemplo de XML
|
Um original de XML é dado abaixo.
|
<?xml version="1.0" encoding="ISO-8859-1"?><bookstore><book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book><book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book></bookstore>
|
Selecionando nós
|
Para selecionar expressões do trajeto dos usos de XPath dos nós. O nó é selecionado seguindo um trajeto. As expressões as mais úteis do trajeto são: -
|
Expression |
Description |
nodename |
Selects all child nodes of the node |
/ |
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 current node |
.. |
Selects the parent of the current node |
@ |
Selects attributes |
Exemplo
|
Tabela dada abaixo nós alistamos algumas expressões do trajeto e o resultado das expressões:
|
Path Expression |
Result |
bookstore |
Selects all the child nodes of the bookstore element |
/bookstore |
Selects the root element bookstore
Note: If the path starts with a slash ( / ) it always
represents an absolute path to an element! |
bookstore/book |
Selects all book elements that are children of
bookstore |
//book |
Selects all book elements no matter where they are in
the document |
bookstore//book |
Selects all book elements that are descendant of the
bookstore element, no matter where they are under the bookstore element |
//@lang |
Selects all attributes that are named lang |
Predicados
|
Os predicados são usados encontrar um nó específico que contenha um valor. Os predicados são encaixados sempre nos suportes quadrados.
|
Exemplo
|
Tabela dada abaixo nós alistamos algumas expressões do trajeto com predicados e o resultado das expressões:
|
Path Expression |
Result |
/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='eng'] |
Selects all the title elements that have an attribute
named lang with a value of 'eng' |
/bookstore/book[price>35.00] |
Selects all the book elements of the bookstore element
that have a price element with a value greater than 35.00 |
/bookstore/book[price>35.00]/title |
Selects all the title elements of the book elements of
the bookstore element that have a price element with a value greater
than 35.00 |
Como nós que selecionamos nós desconhecidos?
|
Os Wildcards podem ser usados selecionar elementos desconhecidos de XML.
|
Wildcard |
Description |
* |
Matches any element node |
@* |
Matches any attribute node |
node() |
Matches any node of any kind |
Exemplo
|
Tabela dada abaixo nós alistamos algumas expressões do trajeto e o resultado das expressões:
|
Path Expression |
Result |
/bookstore/* |
Selects all the child nodes of the bookstore element |
//* |
Selects all elements in the document |
//title[@*] |
Selects all title elements which have any attribute |
|
|
Keywords: A sintaxe de XPath, sintaxe da pergunta do xpath, sintaxe do xsl, rede do vb do xpath, sintaxe do xslt, xpath líquido do asp, xpath começa com, sintaxe do xquery, sintaxe líquida do vb, caso insensitive, sintaxe líquida do xpath do asp, referência do xpath, tutorial do xpath, exemplos do xpath, sintaxe do xml, namespace do xpath, expressões do xpath, c# do xpath, namespaces do xpath, xml do xpath, sintaxe do cdata, xpath funciona, xpath do selectsinglenode, exemplo do xpath, sintaxe do c#, xpath do xsl, pergunta do xpath, sintaxe do DTD, atributo do xpath, xpath contem, xslt do xpath, xmlns do xpath, xpath do xquery, expressão do xpath, xpath do Javascript, sorte do xpath, sintaxe do stylesheet, selectnodes do xpath, atributos do xpath, nome do xpath, perguntas do xpath, xpath dom4j, sintaxe do xhtml, HTML do xpath, cdata do xpath, sintaxe do xsd, predicados do xpath, xpath w3c, sintaxe do css, sintaxe do HTML, contagem do xpath, texto do xpath, linha central do xpath, xpath do xmldocument, sintaxe do uri, xpath ou, xpath xalan, sintaxe do Javascript, original do xpath, xpath do jdom, Perl do xpath, posição do xpath, predicado do xpath, substring do xpath, amostra do xpath, xpath sql, sintaxe do namespace, sintaxe dos exemplos, sintaxe do Perl, xpath do msxml
|