<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >XML, Analisadores</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Referência das Funções" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="xdiff_string_patch" HREF="function.xdiff-string-patch.html"><LINK REL="NEXT" TITLE="utf8_decode" HREF="function.utf8-decode.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.xdiff-string-patch.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.utf8-decode.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.xml" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >CLXXIX. XML, Analisadores</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN233695" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="xml.intro" >Introdução</A ></H1 ><P > XML (eXtensible Markup Language) é um formato de dados para intercâmbio de documentos na Web. Ele é um padrão definido pela The World Wide Web consortium (W3C). Informações sobre XML e tecnologias relacionadas pode, ser encontradas em <A HREF="http://www.w3.org/XML/" TARGET="_top" >http://www.w3.org/XML/</A >. </P ><P > Esta extensão do PHP implementa suporte para o James Clark's <SPAN CLASS="productname" >expat</SPAN > no PHP. Esta ferramenta permite que você analise, mas não valide, documentos XML. Ele suporta três source <A HREF="ref.xml.html#xml.encoding" >character encodings</A > também fornecido pelo PHP: <TT CLASS="literal" >US-ASCII</TT >, <TT CLASS="literal" >ISO-8859-1</TT > e <TT CLASS="literal" >UTF-8</TT >. <TT CLASS="literal" >UTF-16</TT > não é suportado. </P ><P > Esta extensão te permite <A HREF="function.xml-parser-create.html" >criar analisadores XML</A > e então definir <SPAN CLASS="emphasis" ><I CLASS="emphasis" >manipuladores (handlers)</I ></SPAN > para diferentes eventos XML. Cada analisador XML também tem alguns <A HREF="function.xml-parser-set-option.html" >parâmetros</A > que você pode ajustar. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="xml.requirements" >Dependências</A ></H1 ><P > Esta extensão utiliza o <SPAN CLASS="productname" >expat</SPAN >, que pode ser encontrado em <A HREF="http://www.jclark.com/xml/expat.html" TARGET="_top" >http://www.jclark.com/xml/expat.html</A >. O makefile que vem com o expat, por definição não constrói uma biblioteca, você pode usar as regras de 'make' para isso: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="makefile" >libexpat.a: $(OBJS) ar -rc $@ $(OBJS) ranlib $@</PRE ></TD ></TR ></TABLE > Um pacote dos fontes RPM do expat podem ser encontrados em <A HREF="http://sourceforge.net/projects/expat/" TARGET="_top" >http://sourceforge.net/projects/expat/</A >. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="xml.installation" >Instalação</A ></H1 ><P > Estas funções estão por definição habilitadas, usando o pacote expat library. Você pode desabilitar o suporte a XML com <CODE CLASS="option" >--disable-xml</CODE >. Se você compilou o PHP como um módulo do Apache 1.3.9 ou mais novo, o PHP automaticamente utilizará o pacote <SPAN CLASS="productname" >expat</SPAN > library do Apache. Regularmente você não quer utilizar a configuração do pacote expat library do PHP <CODE CLASS="option" >--with-expat-dir=DIR</CODE >, onde DIR apontaria para o diretório base de instalação do expat. </P ><P >A versão para Windows do <TT CLASS="literal" >PHP</TT > tem suporte embutido para esta extensão. Você não precisa carregar nenhuma extensão adicional para utilizar essas funções.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="xml.configuration" >Configurações em execução</A ></H1 ><P >Esta extensão não define nenhum parâmetro de configuração no <TT CLASS="filename" >php.ini</TT >.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="xml.resources" >Tipos Resource</A ></H1 ><DIV CLASS="section" ><H2 CLASS="section" ><A NAME="xml.resources.xml" ><TT CLASS="literal" >xml</TT ></A ></H2 ><P > O recurso <TT CLASS="literal" >xml</TT > enquanto retornado por <A HREF="function.xml-parser-create.html" ><B CLASS="function" >xml_parser_create()</B ></A > e <A HREF="function.xml-parser-create-ns.html" ><B CLASS="function" >xml_parser_create_ns()</B ></A > refere-se a uma instância do analisador xml para ser usada coms as funções fornecidas por esta extensão. </P ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="xml.constants" >Constantes pré-definidas</A ></H1 ><P > As contantes abaixo são definidas por esta extensão e somente estarão disponíveis quando a extensão foi compilada com o PHP ou carregada dinamicamente durante a execução. </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >XML_ERROR_NONE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_NO_MEMORY</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_SYNTAX</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_NO_ELEMENTS</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_INVALID_TOKEN</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_UNCLOSED_TOKEN</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_PARTIAL_CHAR</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_TAG_MISMATCH</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_DUPLICATE_ATTRIBUTE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_JUNK_AFTER_DOC_ELEMENT</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_PARAM_ENTITY_REF</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_UNDEFINED_ENTITY</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_RECURSIVE_ENTITY_REF</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_ASYNC_ENTITY</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_BAD_CHAR_REF</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_BINARY_ENTITY_REF</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_MISPLACED_XML_PI</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_UNKNOWN_ENCODING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_INCORRECT_ENCODING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_UNCLOSED_CDATA_SECTION</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_ERROR_EXTERNAL_ENTITY_HANDLING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_OPTION_CASE_FOLDING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_OPTION_TARGET_ENCODING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_OPTION_SKIP_TAGSTART</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >XML_OPTION_SKIP_WHITE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="xml.eventhandlers" >Manipuladores (handlers) de Evento</A ></H1 ><P > Os manipuladores (handlers) de eventos de XML definidos são: <DIV CLASS="table" ><A NAME="AEN233902" ></A ><P ><B >Tabela 1. Manipuladores XML Suportados</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >função do PHP para definir o manipulador(handler)</TH ><TH >Descrição do evento</TH ></TR ></THEAD ><TBODY ><TR ><TD ><A HREF="function.xml-set-element-handler.html" ><B CLASS="function" >xml_set_element_handler()</B ></A ></TD ><TD > Eventos elementares são emitidos toda vez que o analisador XML o início ou o fim das tags. Há manipuladores (handlers) separadores para tags de início e tags de fim. </TD ></TR ><TR ><TD > <A HREF="function.xml-set-character-data-handler.html" ><B CLASS="function" >xml_set_character_data_handler()</B ></A > </TD ><TD > Dados de caractere são aproximadamente todo o conteúdo de documentos XML, incluindo espaços em branco entre as tags. Note que o analisador XML não adiciona ou remove qualquer espaço em branco, ele está pronto para a aplicação se você decidir que espaços em branco são significativos. </TD ></TR ><TR ><TD > <A HREF="function.xml-set-processing-instruction-handler.html" ><B CLASS="function" >xml_set_processing_instruction_handler()</B ></A > </TD ><TD > Programadores de PHP já estariam familiarizados com instruções de processo (PIs). <?php ?> é uma instrução de processo, onde <TT CLASS="replaceable" ><I >php</I ></TT > é chamada de o "PI target". O tratamento destes são application-specific, exceto que todos os PI targets iniciados com "XML" estão reservados. </TD ></TR ><TR ><TD ><A HREF="function.xml-set-default-handler.html" ><B CLASS="function" >xml_set_default_handler()</B ></A ></TD ><TD > O que não vai para outro manipulador vai para o manipulador padrão. Você conseguirá coisas como o XML e declarações do tipo de documento no manipulador padrão. </TD ></TR ><TR ><TD > <A HREF="function.xml-set-unparsed-entity-decl-handler.html" ><B CLASS="function" >xml_set_unparsed_entity_decl_handler()</B ></A > </TD ><TD > Este manipulador será chamado por uma declaração de um entity não analisada (NDATA). </TD ></TR ><TR ><TD > <A HREF="function.xml-set-notation-decl-handler.html" ><B CLASS="function" >xml_set_notation_decl_handler()</B ></A > </TD ><TD > Este manipulador é chamado pela declaração de uma nota. </TD ></TR ><TR ><TD > <A HREF="function.xml-set-external-entity-ref-handler.html" ><B CLASS="function" >xml_set_external_entity_ref_handler()</B ></A > </TD ><TD > Este manipulador é chamado quando o analisador XML encontra uma referência para uma entity geral analizada externamente. Isto pode ser uma referência para um arquivo ou URL, por examplo. Veja <A HREF="ref.xml.html#example.xml-external-entity" >Um exemplo de entity externa</A > para uma demonstração. </TD ></TR ></TBODY ></TABLE ></DIV > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="xml.case-folding" >Case Folding</A ></H1 ><P > As funções de elementos do manipulador podem conseguir os nomes dos elementos <I CLASS="glossterm" >case-folded</I >. Case-folding é definida pelo padrão XML como "um processo aplicado para uma sequência de caracateres, em que aqueles identificados como minúsculos são substituidos pelos seus maiúsculos equivalentes". Em outras palavras, quando vai pro XML, case-folding simplesmente significa mudar pra maiúsculas. </P ><P > Por definição, todos os nomes de elementos que são passados para as funções de manipulador são case-folded. Este comportamento pode ser perguntado e controlado pelo analisador XML com o <A HREF="function.xml-parser-get-option.html" ><B CLASS="function" >xml_parser_get_option()</B ></A > e as funções <A HREF="function.xml-parser-set-option.html" ><B CLASS="function" >xml_parser_set_option()</B ></A >, respectivamente. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="xml.error-codes" >Error Codes</A ></H1 ><P > As seguintes constantes são definidas para erros no código XML (conforme retornado por <A HREF="function.xml-parse.html" ><B CLASS="function" >xml_parse()</B ></A >): <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD >XML_ERROR_NONE</TD ></TR ><TR ><TD >XML_ERROR_NO_MEMORY</TD ></TR ><TR ><TD >XML_ERROR_SYNTAX</TD ></TR ><TR ><TD >XML_ERROR_NO_ELEMENTS</TD ></TR ><TR ><TD >XML_ERROR_INVALID_TOKEN</TD ></TR ><TR ><TD >XML_ERROR_UNCLOSED_TOKEN</TD ></TR ><TR ><TD >XML_ERROR_PARTIAL_CHAR</TD ></TR ><TR ><TD >XML_ERROR_TAG_MISMATCH</TD ></TR ><TR ><TD >XML_ERROR_DUPLICATE_ATTRIBUTE</TD ></TR ><TR ><TD >XML_ERROR_JUNK_AFTER_DOC_ELEMENT</TD ></TR ><TR ><TD >XML_ERROR_PARAM_ENTITY_REF</TD ></TR ><TR ><TD >XML_ERROR_UNDEFINED_ENTITY</TD ></TR ><TR ><TD >XML_ERROR_RECURSIVE_ENTITY_REF</TD ></TR ><TR ><TD >XML_ERROR_ASYNC_ENTITY</TD ></TR ><TR ><TD >XML_ERROR_BAD_CHAR_REF</TD ></TR ><TR ><TD >XML_ERROR_BINARY_ENTITY_REF</TD ></TR ><TR ><TD >XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF</TD ></TR ><TR ><TD >XML_ERROR_MISPLACED_XML_PI</TD ></TR ><TR ><TD >XML_ERROR_UNKNOWN_ENCODING</TD ></TR ><TR ><TD >XML_ERROR_INCORRECT_ENCODING</TD ></TR ><TR ><TD >XML_ERROR_UNCLOSED_CDATA_SECTION</TD ></TR ><TR ><TD >XML_ERROR_EXTERNAL_ENTITY_HANDLING</TD ></TR ></TBODY ></TABLE ><P ></P > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="xml.encoding" >Codificação de Caracter</A ></H1 ><P > A Extensão XML do PHP suporta o caracter <A HREF="http://www.unicode.org/" TARGET="_top" >Unicode</A > definido por <I CLASS="glossterm" >character encoding</I >s (codificação de caracteres) diferentes. Há dois tipos de codificação de caracteres, <I CLASS="glossterm" >source encoding</I > e <I CLASS="glossterm" > target encoding</I >. A apresentação interna do PHP do documento é sempre codificada com <TT CLASS="literal" >UTF-8</TT >. </P ><P > Source encoding é feita quando um documento XML é <A HREF="function.xml-parse.html" >analisado</A >. Em <A HREF="function.xml-parser-create.html" > criando um analisador XML</A >, um source encoding pode ser especificado (Esta codificação não poderá ser mudada após o tempo de vida do analisador XML). As codificações suportadas são <TT CLASS="literal" >ISO-8859-1</TT >, <TT CLASS="literal" >US-ASCII</TT > e <TT CLASS="literal" >UTF-8</TT >. O segundo são codificações single-byte, que significa que cada caractere é representado por um byte simples. <TT CLASS="literal" >UTF-8</TT > pode codificar caracteres compostos por um número de bits variável (acima de 21) em um de seus 4 bytes. O source encoding padrão utilizado pelo PHP é <TT CLASS="literal" >ISO-8859-1</TT >. </P ><P > Target encoding é feito quando o PHP passa dados para as funções do analisador XML. Quando um analisador XML é criado, o target encoding é definido igual ao source encoding, mas este pode ser mudado em qualquer ponto. O target encoding afetará dados de caracter tão bem como nome de tags e processando alvos da instrução. </P ><P > Se o analisador XML encontra caracteres de fora da linha que seu source encoding é capaz de detalhar, ele retornará um erro. </P ><P > Se PHP encontra caracteres no documento XML analisado que não podem ser detalhados selecionados com target encoding, os caracteres com problema serão "demoted". Atualmente, isto significa que tais caracteres serão substituidos por um sinal de interrogação. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="xml.examples" >Exemplos</A ></H1 ><P > Aqui estão alguns exemplos de scripts PHP analisando documentos XML. </P ><DIV CLASS="section" ><H2 CLASS="section" ><A NAME="example.xml-structure" >Exemplo estruturado de elementos XML</A ></H2 ><P > Este primeiro exemplo mostra a estrutura de elementos iniciais num documento com distanciamento da margem. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN233999" ></A ><P ><B >Exemplo 1. Mostra estrutura do elemento XML </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$file </font><font color="#007700">= </font><font color="#DD0000">"data.xml"</font><font color="#007700">;<br /></font><font color="#0000BB">$depth </font><font color="#007700">= array();<br /><br />function </font><font color="#0000BB">startElement</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$name</font><font color="#007700">, </font><font color="#0000BB">$attrs</font><font color="#007700">) {<br /> global </font><font color="#0000BB">$depth</font><font color="#007700">;<br /> for (</font><font color="#0000BB">$i </font><font color="#007700">= </font><font color="#0000BB">0</font><font color="#007700">; </font><font color="#0000BB">$i </font><font color="#007700">< </font><font color="#0000BB">$depth</font><font color="#007700">[</font><font color="#0000BB">$parser</font><font color="#007700">]; </font><font color="#0000BB">$i</font><font color="#007700">++) {<br /> echo </font><font color="#DD0000">" "</font><font color="#007700">;<br /> }<br /> echo </font><font color="#DD0000">"$name</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">;<br /> </font><font color="#0000BB">$depth</font><font color="#007700">[</font><font color="#0000BB">$parser</font><font color="#007700">]++;<br />}<br /><br />function </font><font color="#0000BB">endElement</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$name</font><font color="#007700">) {<br /> global </font><font color="#0000BB">$depth</font><font color="#007700">;<br /> </font><font color="#0000BB">$depth</font><font color="#007700">[</font><font color="#0000BB">$parser</font><font color="#007700">]--;<br />}<br /><br /></font><font color="#0000BB">$xml_parser </font><font color="#007700">= </font><font color="#0000BB">xml_parser_create</font><font color="#007700">();<br /></font><font color="#0000BB">xml_set_element_handler</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#DD0000">"startElement"</font><font color="#007700">, </font><font color="#DD0000">"endElement"</font><font color="#007700">);<br />if (!(</font><font color="#0000BB">$fp </font><font color="#007700">= </font><font color="#0000BB">fopen</font><font color="#007700">(</font><font color="#0000BB">$file</font><font color="#007700">, </font><font color="#DD0000">"r"</font><font color="#007700">))) {<br /> die(</font><font color="#DD0000">"could not open XML input"</font><font color="#007700">);<br />}<br /><br />while (</font><font color="#0000BB">$data </font><font color="#007700">= </font><font color="#0000BB">fread</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">, </font><font color="#0000BB">4096</font><font color="#007700">)) {<br /> if (!</font><font color="#0000BB">xml_parse</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#0000BB">$data</font><font color="#007700">, </font><font color="#0000BB">feof</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">))) {<br /> die(</font><font color="#0000BB">sprintf</font><font color="#007700">(</font><font color="#DD0000">"XML error: %s at line %d"</font><font color="#007700">,<br /> </font><font color="#0000BB">xml_error_string</font><font color="#007700">(</font><font color="#0000BB">xml_get_error_code</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">)),<br /> </font><font color="#0000BB">xml_get_current_line_number</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">)));<br /> }<br />}<br /></font><font color="#0000BB">xml_parser_free</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="section" ><H2 CLASS="section" ><A NAME="example.xml-map-tags" >Exemplo arrumação de Tag XML</A ></H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN234005" ></A ><P ><B >Exemplo 2. Arrumar XML to HTML</B ></P ><P > Este exemplo arruma tags do documento XML diretamente para tags HTML. Elementos não encontrados no "array de arrumação" são ignorados. É claro, este exemplo trabalhará apenas com um tipo de documento XML específico. </P ><P > <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$file </font><font color="#007700">= </font><font color="#DD0000">"data.xml"</font><font color="#007700">;<br /></font><font color="#0000BB">$map_array </font><font color="#007700">= array(<br /> </font><font color="#DD0000">"BOLD" </font><font color="#007700">=> </font><font color="#DD0000">"B"</font><font color="#007700">,<br /> </font><font color="#DD0000">"EMPHASIS" </font><font color="#007700">=> </font><font color="#DD0000">"I"</font><font color="#007700">,<br /> </font><font color="#DD0000">"LITERAL" </font><font color="#007700">=> </font><font color="#DD0000">"TT"<br /></font><font color="#007700">);<br /><br />function </font><font color="#0000BB">startElement</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$name</font><font color="#007700">, </font><font color="#0000BB">$attrs</font><font color="#007700">) {<br /> global </font><font color="#0000BB">$map_array</font><font color="#007700">;<br /> if (</font><font color="#0000BB">$htmltag </font><font color="#007700">== </font><font color="#0000BB">$map_array</font><font color="#007700">[</font><font color="#0000BB">$name</font><font color="#007700">]) {<br /> echo </font><font color="#DD0000">"<$htmltag>"</font><font color="#007700">;<br /> }<br />}<br /><br />function </font><font color="#0000BB">endElement</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$name</font><font color="#007700">) {<br /> global </font><font color="#0000BB">$map_array</font><font color="#007700">;<br /> if (</font><font color="#0000BB">$htmltag </font><font color="#007700">== </font><font color="#0000BB">$map_array</font><font color="#007700">[</font><font color="#0000BB">$name</font><font color="#007700">]) {<br /> echo </font><font color="#DD0000">"</$htmltag>"</font><font color="#007700">;<br /> }<br />}<br /><br />function </font><font color="#0000BB">characterData</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$data</font><font color="#007700">) {<br /> echo </font><font color="#0000BB">$data</font><font color="#007700">;<br />}<br /><br /></font><font color="#0000BB">$xml_parser </font><font color="#007700">= </font><font color="#0000BB">xml_parser_create</font><font color="#007700">();<br /></font><font color="#FF8000">// use case-folding so we are sure to find the tag in $map_array<br /></font><font color="#0000BB">xml_parser_set_option</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#0000BB">XML_OPTION_CASE_FOLDING</font><font color="#007700">, </font><font color="#0000BB">true</font><font color="#007700">);<br /></font><font color="#0000BB">xml_set_element_handler</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#DD0000">"startElement"</font><font color="#007700">, </font><font color="#DD0000">"endElement"</font><font color="#007700">);<br /></font><font color="#0000BB">xml_set_character_data_handler</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#DD0000">"characterData"</font><font color="#007700">);<br />if (!(</font><font color="#0000BB">$fp </font><font color="#007700">= </font><font color="#0000BB">fopen</font><font color="#007700">(</font><font color="#0000BB">$file</font><font color="#007700">, </font><font color="#DD0000">"r"</font><font color="#007700">))) {<br /> die(</font><font color="#DD0000">"could not open XML input"</font><font color="#007700">);<br />}<br /><br />while (</font><font color="#0000BB">$data </font><font color="#007700">= </font><font color="#0000BB">fread</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">, </font><font color="#0000BB">4096</font><font color="#007700">)) {<br /> if (!</font><font color="#0000BB">xml_parse</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#0000BB">$data</font><font color="#007700">, </font><font color="#0000BB">feof</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">))) {<br /> die(</font><font color="#0000BB">sprintf</font><font color="#007700">(</font><font color="#DD0000">"XML error: %s at line %d"</font><font color="#007700">,<br /> </font><font color="#0000BB">xml_error_string</font><font color="#007700">(</font><font color="#0000BB">xml_get_error_code</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">)),<br /> </font><font color="#0000BB">xml_get_current_line_number</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">)));<br /> }<br />}<br /></font><font color="#0000BB">xml_parser_free</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE > </P ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="section" ><H2 CLASS="section" ><A NAME="example.xml-external-entity" >Exemplo XML de Entity externa</A ></H2 ><P > Este exemplo destaca o código XML. Ele ilusta como utilizar um analisador de referência a uma entity externa para incluir e analisar outros documentos, tão bem como PIs (instruções de processo) podem ser processadas, e uma forma de determinar "trust" para PIs contendo códigos. </P ><P > Documentos XML que podem ser utilizados para este exemplo são encontrados abaixo do exemplo (<TT CLASS="filename" >xmltest.xml</TT > e <TT CLASS="filename" >xmltest2.xml</TT >.) </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN234017" ></A ><P ><B >Exemplo 3. Exemplo de Entity externa</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$file </font><font color="#007700">= </font><font color="#DD0000">"xmltest.xml"</font><font color="#007700">;<br /><br />function </font><font color="#0000BB">trustedFile</font><font color="#007700">(</font><font color="#0000BB">$file</font><font color="#007700">) {<br /> </font><font color="#FF8000">// only trust local files owned by ourselves<br /> </font><font color="#007700">if (!</font><font color="#0000BB">eregi</font><font color="#007700">(</font><font color="#DD0000">"^([a-z]+)://"</font><font color="#007700">, </font><font color="#0000BB">$file</font><font color="#007700">) <br /> && </font><font color="#0000BB">fileowner</font><font color="#007700">(</font><font color="#0000BB">$file</font><font color="#007700">) == </font><font color="#0000BB">getmyuid</font><font color="#007700">()) {<br /> return </font><font color="#0000BB">true</font><font color="#007700">;<br /> }<br /> return </font><font color="#0000BB">false</font><font color="#007700">;<br />}<br /><br />function </font><font color="#0000BB">startElement</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$name</font><font color="#007700">, </font><font color="#0000BB">$attribs</font><font color="#007700">) {<br /> echo </font><font color="#DD0000">"&lt;<font color=</font><font color="#007700">\"</font><font color="#DD0000">#0000cc</font><font color="#007700">\"</font><font color="#DD0000">>$name</font>"</font><font color="#007700">;<br /> if (</font><font color="#0000BB">sizeof</font><font color="#007700">(</font><font color="#0000BB">$attribs</font><font color="#007700">)) {<br /> while (list(</font><font color="#0000BB">$k</font><font color="#007700">, </font><font color="#0000BB">$v</font><font color="#007700">) = </font><font color="#0000BB">each</font><font color="#007700">(</font><font color="#0000BB">$attribs</font><font color="#007700">)) {<br /> echo </font><font color="#DD0000">" <font color=</font><font color="#007700">\"</font><font color="#DD0000">#009900</font><font color="#007700">\"</font><font color="#DD0000">>$k</font>=</font><font color="#007700">\"</font><font color="#DD0000"><font <br /> color=</font><font color="#007700">\"</font><font color="#DD0000">#990000</font><font color="#007700">\"</font><font color="#DD0000">>$v</font></font><font color="#007700">\"</font><font color="#DD0000">"</font><font color="#007700">;<br /> }<br /> }<br /> echo </font><font color="#DD0000">"&gt;"</font><font color="#007700">;<br />}<br /><br />function </font><font color="#0000BB">endElement</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$name</font><font color="#007700">) {<br /> echo </font><font color="#DD0000">"&lt;/<font color=</font><font color="#007700">\"</font><font color="#DD0000">#0000cc</font><font color="#007700">\"</font><font color="#DD0000">>$name</font>&gt;"</font><font color="#007700">;<br />}<br /><br />function </font><font color="#0000BB">characterData</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$data</font><font color="#007700">) {<br /> echo </font><font color="#DD0000">"<b>$data</b>"</font><font color="#007700">;<br />}<br /><br />function </font><font color="#0000BB">PIHandler</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$target</font><font color="#007700">, </font><font color="#0000BB">$data</font><font color="#007700">) {<br /> switch (</font><font color="#0000BB">strtolower</font><font color="#007700">(</font><font color="#0000BB">$target</font><font color="#007700">)) {<br /> case </font><font color="#DD0000">"php"</font><font color="#007700">:<br /> global </font><font color="#0000BB">$parser_file</font><font color="#007700">;<br /> </font><font color="#FF8000">// If the parsed document is "trusted", we say it is safe<br /> // to execute PHP code inside it. If not, display the code<br /> // instead.<br /> </font><font color="#007700">if (</font><font color="#0000BB">trustedFile</font><font color="#007700">(</font><font color="#0000BB">$parser_file</font><font color="#007700">[</font><font color="#0000BB">$parser</font><font color="#007700">])) {<br /> eval(</font><font color="#0000BB">$data</font><font color="#007700">);<br /> } else {<br /> </font><font color="#0000BB">printf</font><font color="#007700">(</font><font color="#DD0000">"Untrusted PHP code: <i>%s</i>"</font><font color="#007700">, <br /> </font><font color="#0000BB">htmlspecialchars</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">));<br /> }<br /> break;<br /> }<br />}<br /><br />function </font><font color="#0000BB">defaultHandler</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$data</font><font color="#007700">) {<br /> if (</font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">) == </font><font color="#DD0000">"&" </font><font color="#007700">&& </font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">, -</font><font color="#0000BB">1</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">) == </font><font color="#DD0000">";"</font><font color="#007700">) {<br /> </font><font color="#0000BB">printf</font><font color="#007700">(</font><font color="#DD0000">'<font color="#aa00aa">%s</font>'</font><font color="#007700">, <br /> </font><font color="#0000BB">htmlspecialchars</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">));<br /> } else {<br /> </font><font color="#0000BB">printf</font><font color="#007700">(</font><font color="#DD0000">'<font size="-1">%s</font>'</font><font color="#007700">, <br /> </font><font color="#0000BB">htmlspecialchars</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">));<br /> }<br />}<br /><br />function </font><font color="#0000BB">externalEntityRefHandler</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$openEntityNames</font><font color="#007700">, </font><font color="#0000BB">$base</font><font color="#007700">, </font><font color="#0000BB">$systemId</font><font color="#007700">,<br /> </font><font color="#0000BB">$publicId</font><font color="#007700">) {<br /> if (</font><font color="#0000BB">$systemId</font><font color="#007700">) {<br /> if (!list(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$fp</font><font color="#007700">) = </font><font color="#0000BB">new_xml_parser</font><font color="#007700">(</font><font color="#0000BB">$systemId</font><font color="#007700">)) {<br /> </font><font color="#0000BB">printf</font><font color="#007700">(</font><font color="#DD0000">"Could not open entity %s at %s\n"</font><font color="#007700">, </font><font color="#0000BB">$openEntityNames</font><font color="#007700">,<br /> </font><font color="#0000BB">$systemId</font><font color="#007700">);<br /> return </font><font color="#0000BB">false</font><font color="#007700">;<br /> }<br /> while (</font><font color="#0000BB">$data </font><font color="#007700">= </font><font color="#0000BB">fread</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">, </font><font color="#0000BB">4096</font><font color="#007700">)) {<br /> if (!</font><font color="#0000BB">xml_parse</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">, </font><font color="#0000BB">$data</font><font color="#007700">, </font><font color="#0000BB">feof</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">))) {<br /> </font><font color="#0000BB">printf</font><font color="#007700">(</font><font color="#DD0000">"XML error: %s at line %d while parsing entity %s\n"</font><font color="#007700">,<br /> </font><font color="#0000BB">xml_error_string</font><font color="#007700">(</font><font color="#0000BB">xml_get_error_code</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">)),<br /> </font><font color="#0000BB">xml_get_current_line_number</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">), </font><font color="#0000BB">$openEntityNames</font><font color="#007700">);<br /> </font><font color="#0000BB">xml_parser_free</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">);<br /> return </font><font color="#0000BB">false</font><font color="#007700">;<br /> }<br /> }<br /> </font><font color="#0000BB">xml_parser_free</font><font color="#007700">(</font><font color="#0000BB">$parser</font><font color="#007700">);<br /> return </font><font color="#0000BB">true</font><font color="#007700">;<br /> }<br /> return </font><font color="#0000BB">false</font><font color="#007700">;<br />}<br /><br />function </font><font color="#0000BB">new_xml_parser</font><font color="#007700">(</font><font color="#0000BB">$file</font><font color="#007700">) {<br /> global </font><font color="#0000BB">$parser_file</font><font color="#007700">;<br /><br /> </font><font color="#0000BB">$xml_parser </font><font color="#007700">= </font><font color="#0000BB">xml_parser_create</font><font color="#007700">();<br /> </font><font color="#0000BB">xml_parser_set_option</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#0000BB">XML_OPTION_CASE_FOLDING</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">);<br /> </font><font color="#0000BB">xml_set_element_handler</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#DD0000">"startElement"</font><font color="#007700">, </font><font color="#DD0000">"endElement"</font><font color="#007700">);<br /> </font><font color="#0000BB">xml_set_character_data_handler</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#DD0000">"characterData"</font><font color="#007700">);<br /> </font><font color="#0000BB">xml_set_processing_instruction_handler</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#DD0000">"PIHandler"</font><font color="#007700">);<br /> </font><font color="#0000BB">xml_set_default_handler</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#DD0000">"defaultHandler"</font><font color="#007700">);<br /> </font><font color="#0000BB">xml_set_external_entity_ref_handler</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#DD0000">"externalEntityRefHandler"</font><font color="#007700">);<br /> <br /> if (!(</font><font color="#0000BB">$fp </font><font color="#007700">= @</font><font color="#0000BB">fopen</font><font color="#007700">(</font><font color="#0000BB">$file</font><font color="#007700">, </font><font color="#DD0000">"r"</font><font color="#007700">))) {<br /> return </font><font color="#0000BB">false</font><font color="#007700">;<br /> }<br /> if (!</font><font color="#0000BB">is_array</font><font color="#007700">(</font><font color="#0000BB">$parser_file</font><font color="#007700">)) {<br /> </font><font color="#0000BB">settype</font><font color="#007700">(</font><font color="#0000BB">$parser_file</font><font color="#007700">, </font><font color="#DD0000">"array"</font><font color="#007700">);<br /> }<br /> </font><font color="#0000BB">$parser_file</font><font color="#007700">[</font><font color="#0000BB">$xml_parser</font><font color="#007700">] = </font><font color="#0000BB">$file</font><font color="#007700">;<br /> return array(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#0000BB">$fp</font><font color="#007700">);<br />}<br /><br />if (!(list(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#0000BB">$fp</font><font color="#007700">) = </font><font color="#0000BB">new_xml_parser</font><font color="#007700">(</font><font color="#0000BB">$file</font><font color="#007700">))) {<br /> die(</font><font color="#DD0000">"could not open XML input"</font><font color="#007700">);<br />}<br /><br />echo </font><font color="#DD0000">"<pre>"</font><font color="#007700">;<br />while (</font><font color="#0000BB">$data </font><font color="#007700">= </font><font color="#0000BB">fread</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">, </font><font color="#0000BB">4096</font><font color="#007700">)) {<br /> if (!</font><font color="#0000BB">xml_parse</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">, </font><font color="#0000BB">$data</font><font color="#007700">, </font><font color="#0000BB">feof</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">))) {<br /> die(</font><font color="#0000BB">sprintf</font><font color="#007700">(</font><font color="#DD0000">"XML error: %s at line %d\n"</font><font color="#007700">,<br /> </font><font color="#0000BB">xml_error_string</font><font color="#007700">(</font><font color="#0000BB">xml_get_error_code</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">)),<br /> </font><font color="#0000BB">xml_get_current_line_number</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">)));<br /> }<br />}<br />echo </font><font color="#DD0000">"</pre>"</font><font color="#007700">;<br />echo </font><font color="#DD0000">"parse complete\n"</font><font color="#007700">;<br /></font><font color="#0000BB">xml_parser_free</font><font color="#007700">(</font><font color="#0000BB">$xml_parser</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN234021" ></A ><P ><B >Exemplo 4. xmltest.xml</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="xml" ><?xml version='1.0'?> <!DOCTYPE chapter SYSTEM "/just/a/test.dtd" [ <!ENTITY plainEntity "FOO entity"> <!ENTITY systemEntity SYSTEM "xmltest2.xml"> ]> <chapter> <TITLE>Título &plainEntity;</TITLE> <para> <informaltable> <tgroup cols="3"> <tbody> <row><entry>a1</entry><entry morerows="1">b1</entry><entry>c1</entry></row> <row><entry>a2</entry><entry>c2</entry></row> <row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row> </tbody> </tgroup> </informaltable> </para> &systemEntity; <section id="about"> <title>Sobre este documento</title> <para> <!-- this is a comment --> <?php echo 'Hi! This is PHP version '.phpversion(); ?> </para> </section> </chapter></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > Este arquivo está incluido de <TT CLASS="filename" >xmltest.xml</TT >: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN234026" ></A ><P ><B >Exemplo 5. xmltest2.xml</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="xml" ><?xml version="1.0"?> <!DOCTYPE foo [ <!ENTITY testEnt "test entity"> ]> <foo> <element attrib="value"/> &testEnt; <?php print "This is some more PHP code being executed."; ?> </foo></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Índice</B ></DT ><DT ><A HREF="function.utf8-decode.html" >utf8_decode</A > -- Converte uma string com caracteres ISO-8859-1 codificadas com UTF-8 para single-byte ISO-8859-1. </DT ><DT ><A HREF="function.utf8-encode.html" >utf8_encode</A > -- Codifica um string ISO-8859-1 para UTF-8</DT ><DT ><A HREF="function.xml-error-string.html" >xml_error_string</A > -- Obtém uma string de erro do analisador XML</DT ><DT ><A HREF="function.xml-get-current-byte-index.html" >xml_get_current_byte_index</A > -- Obtém o índice do byte atual para um analisador XML </DT ><DT ><A HREF="function.xml-get-current-column-number.html" >xml_get_current_column_number</A > -- Obtém o número da coluna atual para um analisador XML </DT ><DT ><A HREF="function.xml-get-current-line-number.html" >xml_get_current_line_number</A > -- Obtém o número da linha para um analisador XML</DT ><DT ><A HREF="function.xml-get-error-code.html" >xml_get_error_code</A > -- Obtém um código de erro do analisador XML</DT ><DT ><A HREF="function.xml-parse-into-struct.html" >xml_parse_into_struct</A > -- Analisa dados XML dentro de uma estrutura de array </DT ><DT ><A HREF="function.xml-parse.html" >xml_parse</A > -- Inicia a análise em um documento XML</DT ><DT ><A HREF="function.xml-parser-create-ns.html" >xml_parser_create_ns</A > -- Cria um analisador XML com suporte a namespace (uma estrutura do XML) </DT ><DT ><A HREF="function.xml-parser-create.html" >xml_parser_create</A > -- cria um analisador XML</DT ><DT ><A HREF="function.xml-parser-free.html" >xml_parser_free</A > -- Free an XML parser</DT ><DT ><A HREF="function.xml-parser-get-option.html" >xml_parser_get_option</A > -- Get options from an XML parser</DT ><DT ><A HREF="function.xml-parser-set-option.html" >xml_parser_set_option</A > -- Set options in an XML parser</DT ><DT ><A HREF="function.xml-set-character-data-handler.html" >xml_set_character_data_handler</A > -- Set up character data handler</DT ><DT ><A HREF="function.xml-set-default-handler.html" >xml_set_default_handler</A > -- Set up default handler</DT ><DT ><A HREF="function.xml-set-element-handler.html" >xml_set_element_handler</A > -- Set up start and end element handlers</DT ><DT ><A HREF="function.xml-set-end-namespace-decl-handler.html" >xml_set_end_namespace_decl_handler</A > -- Set up end namespace declaration handler</DT ><DT ><A HREF="function.xml-set-external-entity-ref-handler.html" >xml_set_external_entity_ref_handler</A > -- Set up external entity reference handler</DT ><DT ><A HREF="function.xml-set-notation-decl-handler.html" >xml_set_notation_decl_handler</A > -- Set up notation declaration handler</DT ><DT ><A HREF="function.xml-set-object.html" >xml_set_object</A > -- Use XML Parser within an object</DT ><DT ><A HREF="function.xml-set-processing-instruction-handler.html" >xml_set_processing_instruction_handler</A > -- Set up processing instruction (PI) handler </DT ><DT ><A HREF="function.xml-set-start-namespace-decl-handler.html" >xml_set_start_namespace_decl_handler</A > -- Set up start namespace declaration handler </DT ><DT ><A HREF="function.xml-set-unparsed-entity-decl-handler.html" >xml_set_unparsed_entity_decl_handler</A > -- Set up unparsed entity declaration handler </DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.xdiff-string-patch.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.utf8-decode.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >xdiff_string_patch</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >utf8_decode</TD ></TR ></TABLE ></DIV ></BODY ></HTML >