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
|