Reemplazar Entidades

Tengo un archivo XML, con
caracteres Especiales como : &nbsp,
&quot, &apos, etc, mi problema es que
Cuando lo parseo, y lo veo en pantalla,
Estos caracteres no cambian al caracter
Que representan, y al Transformarlo a
HTML, me arroja el error de
"entidad 'nbsp' referenciada, pero no declarada".
Si alguien me pudiera ayudar,
se lo agradeceria.

1 respuesta

Respuesta
1
Hay que distinguir entre las entidades própias del xml y las demas. Tanto ', ", &, <, > tienen entidades reconocidas por el lenguaje xml, encambio el nbsp es un caracter especial que se puede representar con una entidad.
Yo siempre utilizo la directiva encoding='iso-8859-1' en la cabecera xml así puedo utilizar acentos i caracteres españones sin ningún problema.
En caso que quieras utilizar entidades para estos carcateres tienes que crear un fitxero de entidades i incluirlo com si de un dtd se tratara.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE SECTION SYSTEM "../dtd/entitys.dtd">
El fitxero entitys.dtd puedes crearlo haciendo copy paste de esto:
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v3.0 NT (http://www.xmlspy.com) by UIB (UIB) -->
<!-- (C) International Organization for Standardization 1986
Permission to copy in any form is granted for use with
conforming SGML systems and applications as defined in
ISO 8879, provided this notice is included in all copies.
-->
<!-- Character entity set. Typical invocation:
<!ENTITY % ISOdia PUBLIC
"ISO 8879:1986//ENTITIES Diacritical Marks//EN//XML">
%ISOdia;
-->
<!-- This version of the entity set can be used with any SGML document
which uses ISO 10646 as its document character set.
This includes XML documents and ISO HTML documents.
This entity set uses hexadecimal numeric character references.
Creator: Rick Jelliffe, Allette Systems
Version: 1997-07-07
-->
<!ENTITY acute "´">
<!--=acute accent-->
<!ENTITY breve "?">
<!--=breve-->
<!ENTITY caron "?">
<!--=caron-->
<!ENTITY cedil "¸">
<!--=cedilla-->
<!ENTITY circ "^">
<!--=circumflex accent-->
<!ENTITY dblac "?">
<!--=double acute accent-->
<!ENTITY die "¨">
<!--=dieresis-->
<!ENTITY dot "?">
<!--=dot above-->
<!ENTITY grave "`">
<!--=grave accent-->
<!ENTITY macr "¯">
<!--=macron-->
<!ENTITY ogon "?">
<!--=ogonek-->
<!ENTITY ring "?">
<!--=ring-->
<!ENTITY tilde "~">
<!--=tilde-->
<!ENTITY uml "¨">
<!--=umlaut mark-->
<!-- (C) International Organization for Standardization 1986
Permission to copy in any form is granted for use with
conforming SGML systems and applications as defined in
ISO 8879, provided this notice is included in all copies.
Creator: version from ISO 8879:1986
Version: 0.21 1992-12-04
-->
<!-- Character entity set. Typical invocation:
<!ENTITY % ISOGRK1 PUBLIC
"ISO 9573-15:1993//ENTITIES Greek Letters//EN//XML">
%ISOGRK1;
-->
<!-- This version of the entity set can be used with any SGML document
which uses ISO 10646 as its document character set.
This includes XML documents and ISO HTML documents.
Creator: Rick Jelliffe, from HTMLlat1
Version: 1997-07-07
-->
<!ENTITY agr "?">
<!--small alpha, Greek, U03B1 -->
<!ENTITY Agr "?">
<!--capital Alpha, Greek, U0391 -->
<!ENTITY bgr "?">
<!--small beta, Greek, U03B2 -->
<!ENTITY Bgr "?">
<!--capital Beta, Greek, U0392 -->
<!ENTITY ggr "?">
<!--small gamma, Greek, U03B3 -->
<!ENTITY Ggr "?">
<!--capital Gamma, Greek, U0393 --&

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas