Hola amigos necesito esto:
Carácter Especial
& DEBE QUEDAR ASI &
< DEBE QUEDAR ASI <
> DEBE QUEDAR ASI >
“ DEBE QUEDAR ASI "
‘ DEBE QUEDAR ASI '
EJEMPLO:
PINTURA B&W AFECTO
DEBE QUEDAR ASI
PINTURA B&W AFECTO
salduos
TRANFORMAR CARACTER ESPECIALES DE XML
Re: TRANFORMAR CARACTER ESPECIALES DE XML
Hola
Esta rutina la uso , espero te sirva :
En esta rutina evito caracteres que pueden romper la estructura del xml
saludos
Esta rutina la uso , espero te sirva :
Code: Select all
**---------------------------------------------------------------------------**
FUNCTION TRANS_VALIDACADENA(_CADENA)
**---------------------------------------------------------------------------**
LOCAL X:=LEN(_CADENA)
_CADENA := STRTRAN(_CADENA,"&","&")
_CADENA := STRTRAN(_CADENA,">",">")
_CADENA := STRTRAN(_CADENA,"<","<")
_CADENA := STRTRAN(_CADENA,"|","")
_CADENA := STRTRAN(_CADENA,'"',""")
_CADENA := STRTRAN(_CADENA,"'",""")
_CADENA := STRTRAN(_CADENA,"´","'")
_CADENA := STRTRAN(_CADENA,"/","")
_CADENA := STRTRAN(_CADENA,"<-","")
_CADENA := STRTRAN(_CADENA,"->","")
_CADENA := STRTRAN(_CADENA,"<?","")
_CADENA := STRTRAN(_CADENA,"?>","")
_CADENA := STRTRAN(_CADENA,"=","")
_CADENA := STRTRAN(_CADENA,"Á","A")
_CADENA := STRTRAN(_CADENA,"É","E")
_CADENA := STRTRAN(_CADENA,"Í","I")
_CADENA := STRTRAN(_CADENA,"Ó","O")
_CADENA := STRTRAN(_CADENA,"Ú","U")
_CADENA := STRTRAN(_CADENA,"á","a")
_CADENA := STRTRAN(_CADENA,"é","e")
_CADENA := STRTRAN(_CADENA,"í","i")
_CADENA := STRTRAN(_CADENA,"ó","o")
_CADENA := STRTRAN(_CADENA,"ú","u")
_CADENA := STRTRAN(_CADENA,"?","")
_CADENA := STRTRAN(_CADENA,"°","")
_CADENA := STRTRAN(_CADENA,"¡","")
_CADENA := STRTRAN(_CADENA,"!","")
_CADENA := STRTRAN(_CADENA,"¿","")
_CADENA := STRTRAN(_CADENA,"'","")
_CADENA := STRTRAN(_CADENA,"^","")
_CADENA := STRTRAN(_CADENA,"`","")
_CADENA := STRTRAN(_CADENA,"~","")
_CADENA := STRTRAN(_CADENA,"¬","")
_CADENA := STRTRAN(_CADENA,":","")
_CADENA := STRTRAN(_CADENA,"%","")
_CADENA := STRTRAN(_CADENA,"#","")
// para html
//_CADENA := STRTRAN(_CADENA,"ñ","ñ")
//_CADENA := STRTRAN(_CADENA,"Ñ","Ñ")
_CADENA := STRTRAN(_CADENA,"¿","¿")
_CADENA := STRTRAN(_CADENA,"¡","¡")
_CADENA := STRTRAN(_CADENA,"á","á")
_CADENA := STRTRAN(_CADENA,"é","é")
_CADENA := STRTRAN(_CADENA,"í","í")
_CADENA := STRTRAN(_CADENA,"ó","ó")
_CADENA := STRTRAN(_CADENA,"ú","ú")
_CADENA := STRTRAN(_CADENA,"Á","Á")
_CADENA := STRTRAN(_CADENA,"É","É")
_CADENA := STRTRAN(_CADENA,"Í","Í")
_CADENA := STRTRAN(_CADENA,"Ó","Ó")
_CADENA := STRTRAN(_CADENA,"Ú","Ú")
_CADENA := STRTRAN(_CADENA,"ü","ü")
_CADENA := STRTRAN(_CADENA,"Ü","Ü")
/*
Carácter Entidad HTML Carácter Entidad HTML
á á Á Á
é é É É
í í Í Í
ó ó Ó Ó
ú ú Ú Ú
ü ü Ü Ü
ñ ñ Ñ Ñ
¡ ¡ ¿ ¿
*/
RETURN _CADENA
saludos
Visite Chiapas, el paraiso de México.
Re: TRANFORMAR CARACTER ESPECIALES DE XML
eres muy amable, a sido de gran ayuda
saludos
saludos
-
- Posts: 988
- Joined: Thu Nov 24, 2005 3:01 pm
- Location: Madrid, España
Re: TRANFORMAR CARACTER ESPECIALES DE XML
Ampliando la respuesta del compañero Devtuxla, se puede hacer un poco más rápido usando las nuevas funciones de Harbour. Están ahí pero no nos enteramos!
Extraído del Changelog.txt de Harbour
Es decir que en el caso que comentas todo se reduce a :
Este Prezemeck es un genio!
Extraído del Changelog.txt de Harbour
Code: Select all
2013-02-15 01:53 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* harbour/include/harbour.hbx
* harbour/src/rtl/Makefile
+ harbour/src/rtl/strxchg.c
+ added new PRG function:
hb_StrReplace( <cString>, <cSource> | <acSource> | <hReplace>, ;
<cDest> | <acDest> ] ) -> <cResult>
This function allows to easy replace different substrings in
given string.
If 2-nd is string then each character in <cString> which exists
in <cSource> at <n> position is replaced by corresponding character
at <n> position in <cDest> or string from <acDest>[ <n> ]
If 2-nd parameter is array then each <cString> substring which exists
in <acSource> at <n> position is replaced by corresponding character
at <n> position in <cDest> or string from <acDest>[ <n> ].
If <n> is longer then LEN() of <cDest> or <acDest> then given
character/substring is removed from result.
This function should help in code which wrongly uses repeated
StrTran() calls all regex which can change also substituted values.
Examples:
// encode XML value
cXmlText := hb_StrReplace( cText, "<>&", { "<", ">", "&" } )
// now decode it to raw text
cText := hb_StrReplace( cXmlText, { "<", ">", "&" }, "<>&" )
// strip all digits from string
cNoDigit := hb_StrReplace( cText, "0123456789" )
// extract all digits from string
cDigits := hb_StrReplace( cText, cNoDigit )
// convert chosen letters to upper case
? hb_StrReplace( "hello world, "hlwd", "HLWD" )
Code: Select all
cTexto:= hb_StrReplace( cTexto, '&<>"´', { "&", "<", ">", """, "'" } )
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Re: TRANFORMAR CARACTER ESPECIALES DE XML
Carlos,
muchas gracias por la información. Estaremos más atentos al fichero changelog de Harbour.
Saludos
muchas gracias por la información. Estaremos más atentos al fichero changelog de Harbour.
Saludos
-
- Posts: 257
- Joined: Wed May 16, 2007 9:40 pm
- Location: Iquique Chile
Re: TRANFORMAR CARACTER ESPECIALES DE XML
y como se llamaria esta funcion en xharbour...Carlos Mora wrote:Ampliando la respuesta del compañero Devtuxla, se puede hacer un poco más rápido usando las nuevas funciones de Harbour. Están ahí pero no nos enteramos!
Extraído del Changelog.txt de Harbour
Es decir que en el caso que comentas todo se reduce a :Code: Select all
2013-02-15 01:53 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * harbour/include/harbour.hbx * harbour/src/rtl/Makefile + harbour/src/rtl/strxchg.c + added new PRG function: hb_StrReplace( <cString>, <cSource> | <acSource> | <hReplace>, ; <cDest> | <acDest> ] ) -> <cResult> This function allows to easy replace different substrings in given string. If 2-nd is string then each character in <cString> which exists in <cSource> at <n> position is replaced by corresponding character at <n> position in <cDest> or string from <acDest>[ <n> ] If 2-nd parameter is array then each <cString> substring which exists in <acSource> at <n> position is replaced by corresponding character at <n> position in <cDest> or string from <acDest>[ <n> ]. If <n> is longer then LEN() of <cDest> or <acDest> then given character/substring is removed from result. This function should help in code which wrongly uses repeated StrTran() calls all regex which can change also substituted values. Examples: // encode XML value cXmlText := hb_StrReplace( cText, "<>&", { "<", ">", "&" } ) // now decode it to raw text cText := hb_StrReplace( cXmlText, { "<", ">", "&" }, "<>&" ) // strip all digits from string cNoDigit := hb_StrReplace( cText, "0123456789" ) // extract all digits from string cDigits := hb_StrReplace( cText, cNoDigit ) // convert chosen letters to upper case ? hb_StrReplace( "hello world, "hlwd", "HLWD" )
Este Prezemeck es un genio!Code: Select all
cTexto:= hb_StrReplace( cTexto, '&<>"´', { "&", "<", ">", """, "'" } )
Fivewin 11.07