xml
Shared by: xiaopangnv
-
Stats
- views:
- 6
- posted:
- 10/17/2012
- language:
- Portuguese
- pages:
- 16
Document Sample


XML
XML
• O objetivo de XML é ser uma linguagem de marcação
generalizada, com o poder de SGML, porém mais fácil
de implementar.
Marcação Generalizada
• Busca descrever apenas a estrutura do documento,
deixando os detalhes de apresentação para uma folha de
estilos separada. Exemplo:
\keepn \par \sb240 \b0 \hyphpar0 Este é um
paragrafo em RTF.
<par> Este é um parágrafo em XML. </par>
XML e SGML
SGML (1986) XML (1998)
HTML 4.0 (1997) XHTML 1.0 (1990)
HTML 4.1 (1999) WML
JSP
HTML
<html>
<head><title>Exemplo</title></head>
<body>
<p> Um paragrafo
<ul>
<li>item um
<li>item dois
<p> Outro paragrafo com um break <br> no meio.
</body></html>
Sintaxe XML - Tags e Atributos
• Exemplo de XML:
<?xml version=“1.0” ?>
<livro lingua=“portugues” preco=“R$90,00”>
<titulo>Introdução a XML</titulo>
<autor>João da Silva</autor>
</livro>
Documento XML como uma Árvore
document
declaration livro
atributos titulo autor
preco:R$90,00 texto texto
Introducao Joao da
a XML Silva
Sintaxe XML - Tags e Atributos - 2
• Exemplo de tag XML:
<livro lingua=“portugues”>
<!-- Exemplo de tag XML -->
<preco moeda=“R$”>90,00</preco>
<titulo>Introdução a XML</titulo>
<autor>João da Silva</autor>
<editora>Editora Saber</editora>
<edicao num=“3”/>
</livro>
Documentos XML bem formados
• Checa a sintaxe dos tags e atributos.
• Verifica se tags e atributos abrem e fecham corretamente.
• Elementos estão aninhados corretamente.
• Verifica se não há repetição do mesmo atributo para um tag.
Hierarquia dos Tags XML
• XML permite que se defina a hirarquia entre seus tags,
introduzindo assim um segundo nível de sintaxe em seus
documentos.
• Este segundo nível de sintaxe pode ser definido por:
XML DTD
XML Schema
Documentos XML válidos
• Um documento XML é válido quando:
É bem formado
A hierarquia de Tags está de acordo com o DTD ou Schema.
XML bem formado mas não válido
<titulo>Introdução a XML</titulo>
<livro lingua=“portugues”>
<preco moeda=“R$”>90,00</preco>
<autor>João da Silva</autor>
<autor>João da Silva</autor>
<editora>Editora Saber</editora>
<editora>Editora Ignorar</editora>
<edicao num=“3”/>
</livro>
Posição de jogo de xadrez
Posição de jogo de xadrez
<CHESSBOARD>
<WHITEPIECES>
<KING><POSITION COLUMN="G" ROW="1"/></KING>
<BISHOP><POSITION COLUMN="D" ROW="6"/></BISHOP>
<ROOK><POSITION COLUMN="E" ROW="1"/></ROOK>
<PAWN><POSITION COLUMN="A" ROW="4"/></PAWN>
<PAWN><POSITION COLUMN="B" ROW="3"/></PAWN>
<PAWN><POSITION COLUMN="C" ROW="2"/></PAWN>
<PAWN><POSITION COLUMN="F" ROW="2"/></PAWN>
<PAWN><POSITION COLUMN="G" ROW="2"/></PAWN>
<PAWN><POSITION COLUMN="H" ROW="5"/></PAWN>
</WHITEPIECES>
<BLACKPIECES>
<KING><POSITION COLUMN="B" ROW="6"/></KING>
<QUEEN><POSITION COLUMN="A" ROW="7"/></QUEEN>
<PAWN><POSITION COLUMN="A" ROW="5"/></PAWN>
<PAWN><POSITION COLUMN="D" ROW="4"/></PAWN>
</BLACKPIECES>
</CHESSBOARD>
DTD para posição de jogo de xadrez
<!ELEMENT CHESSBOARD (WHITEPIECES, BLACKPIECES)>
<!ENTITY % pieces
"KING,
QUEEN?,
BISHOP?, BISHOP?,
ROOK?, ROOK?,
KNIGHT?, KNIGHT?,
PAWN?, PAWN?, PAWN?, PAWN?,
PAWN?, PAWN?, PAWN?, PAWN?” >
<!ELEMENT WHITEPIECES (%pieces;)>
<!ELEMENT BLACKPIECES (%pieces;)>
<!ELEMENT POSITION EMPTY>
<!ATTLIST POSITION
COLUMN (A|B|C|D|E|F|G|H) #REQUIRED
ROW (1|2|3|4|5|6|7|8) #REQUIRED >
<!ELEMENT KING (POSITION)>
<!ELEMENT QUEEN (POSITION)>
<!ELEMENT BISHOP (POSITION)>
<!ELEMENT ROOK (POSITION)>
<!ELEMENT KNIGHT (POSITION)>
<!ELEMENT PAWN (POSITION)>
Estrutura de um Nó DOM
Interface nodeName nodeValue attributes
Attr name of attribute value of attribute null
CDATASection "#cdata-section" content of the null
CDATA Section
Comment "#comment" content of the null
comment
Document "#document" null null
DocumentFragment "#document- null null
fragment"
DocumentType document type null null
name
Element tag name null NamedNodeMap
Entity entity name null null
EntityReference name of entity null null
referenced
Notation notation name null null
ProcessingInstruction target entire content null
excluding the target
Text "#text" content of the text null
node
Get documents about "