Tutorial de XML

XML INÍCIO Introdução ao XML XML Como usar Árvore XML Sintaxe XML Elementos XML Atributos XML Namespaces XML Exibição XML XML HttpRequest Analisador de XML XML DOM XML XPath XML XSLT XML XQuery XML XLink Validador de XML XML DTD Esquema XML Servidor XML Exemplos XML Teste de XML Certificado XML

XML AJAX

Introdução AJAX AJAX XML Http Solicitação AJAX Resposta AJAX Arquivo XML AJAX PHP AJAX ASP AJAX Banco de dados AJAX Aplicativos AJAX Exemplos AJAX

XML DOM

Introdução ao DOM Nós DOM Acesso ao DOM Informações do nó DOM Lista de nós DOM Travessia do DOM Navegação DOM Valores de obtenção do DOM Nós de alteração do DOM Remoção de nós do DOM Substituir nós DOM DOM Criar nós DOM Adicionar nós Nós clones DOM Exemplos de DOM

Tutorial XPath

Introdução ao XPath Nós XPath Sintaxe XPath Eixos XPath Operadores XPath Exemplos de XPath

Tutorial XSLT

Introdução ao XSLT Idiomas XSL Transformação XSLT XSLT <modelo> XSLT <valor-de> XSLT <para-cada> XSLT <classificar> XSLT <if> XSLT <escolha> Aplicar XSLT XSLT no cliente XSLT no servidor XSLT Editar XML Exemplos de XSLT

Tutorial XQuery

Introdução ao XQuery Exemplo de XQuery XQuery FLWOR XQuery HTML Termos de XQuery Sintaxe XQuery Adicionar XQuery Seleção de XQuery Funções XQuery

XML DTD

Introdução DTD Blocos de construção de DTD Elementos DTD Atributos DTD Elementos DTD vs Attr Entidades DTD Exemplos de DTD

Esquema XSD

Introdução ao XSD XSD Como fazer XSD <esquema> Elementos XSD Atributos XSD Restrições XSD

Complexo XSD

Elementos XSD XSD vazio Apenas elementos XSD Somente texto XSD XSD Misto Indicadores XSD XSD <qualquer> XSD <qualquer atributo> Substituição XSD Exemplo de XSD

Dados XSD

Cadeia XSD Data XSD XSD Numérico XSD Misc Referência XSD

Serviços da Web

Serviços XML XML WSDL XML SOAP XML RDF XML RSS

Referências

Tipos de nós DOM Nó DOM Lista de nós DOM DOM NamedNodeMap Documento DOM Elemento DOM Atributo DOM Texto DOM DOM CDATA Comentário DOM DOM XMLHttpRequest Analisador de DOM Elementos XSLT Funções XSLT/XPath

XML e XPath


O que é XPath?

XPath é um elemento importante no padrão XSLT.

XPath pode ser usado para navegar pelos elementos e atributos em um documento XML.


XPath
  • XPath é uma sintaxe para definir partes de um documento XML
  • XPath usa expressões de caminho para navegar em documentos XML
  • XPath contém uma biblioteca de funções padrão
  • XPath é um elemento importante em XSLT e em XQuery
  • XPath é uma recomendação do W3C

Expressões de caminho XPath

XPath usa expressões de caminho para selecionar nós ou conjuntos de nós em um documento XML. Essas expressões de caminho se parecem muito com as expressões que você vê quando trabalha com um sistema de arquivos de computador tradicional.

Expressões XPath podem ser usadas em JavaScript, Java, XML Schema, PHP, Python, C e C++ e muitas outras linguagens.


XPath é usado em XSLT

XPath é um elemento importante no padrão XSLT.

Com o conhecimento XPath você poderá tirar grande proveito do XSL.



Exemplo de XPath

Usaremos o seguinte documento XML:

<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book category="cooking">
  <title lang="en">Everyday Italian</title>
  <author>Giada De Laurentiis</author>
  <year>2005</year>
  <price>30.00</price>
</book>

<book category="children">
  <title lang="en">Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>

<book category="web">
  <title lang="en">XQuery Kick Start</title>
  <author>James McGovern</author>
  <author>Per Bothner</author>
  <author>Kurt Cagle</author>
  <author>James Linn</author>
  <author>Vaidyanathan Nagarajan</author>
  <year>2003</year>
  <price>49.99</price>
</book>

<book category="web">
  <title lang="en">Learning XML</title>
  <author>Erik T. Ray</author>
  <year>2003</year>
  <price>39.95</price>
</book>

</bookstore>

Na tabela abaixo listamos algumas expressões XPath e o resultado das expressões:

XPath 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='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 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

Tutorial XPath

Você aprenderá muito mais sobre XPath em nosso Tutorial XPath .