Aula03 XML Namespaces XSLT XPath
Aula03 XML Namespaces XSLT XPath
Faculdade de Computação
● Conflitos de Nomes
● Exemplo:
XML Namespaces
<root>
<table>
<tr>
<td>Maçãs</td>
<td>Bananas</td>
</tr>
</table>
<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
</root>
<root>
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
XML Namespaces
– xmlns:prefix = "URI".
XML Namespaces
● Exemplo:
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="https://www.w3schools.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
XML Namespaces
● No exemplo anterior:
<root xmlns:h="http://www.w3.org/TR/html4/"
xmlns:f="https://www.w3schools.com/furniture">
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
XML Namespaces
● Exemplo:
<?xml version="1.0"?>
Elemento
<xsl:stylesheet Root
xmlns="http://www.w3.org/1999/xhtml" Namespace
default
xmlns:book= "http://www.book.com"
xmlns:xsl= "http://www.w3.org/1999/XSL/Transform"
version="1.0">
Expressão
<xsl:template match="/"> Xpath
<html>
<title>Lista de Livros</title>
<body>
<book:title>
<xsl:value-of select ="text[2]/text()"/><br/>
<xsl:value-of select ="text[1]/text()"/><br/>
</book:title>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XML Namespaces
● A declaração
● xmlns=”http://www.w3.org/1999/xhtml”
● Já as declarações
● xmlns:book="http://www.book.com"
● xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
● indicam que...
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
ou:
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
XSLT
● Observações:
<bookstore>
<book>
<title lang="en">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="en">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
XPath
– . Seleciona o nó atual
– @ Seleciona atributos
XPath
● Exemplos:
● Predicados
● Exemplos:
● Exemplos:
● Package javax.xml.xpath
● Fim.
● Prática 02.