XML Caracteres Especiales

XML Caracteres Especiales

Postby mterraz » Wed Aug 14, 2024 12:46 pm

Estimados me encuentro con un problema con los caracteres especiales dentro de un XML. No puedo encontrar una forma efectiva de que los caracteres sea reemplazados/escapados y no rompan el archivo XML.

cPassword:='ugBM08–/Y~]>'

Ejemplo:

<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'+cPassword+'</wsse:Password>

Cuando miro el XML generado la variable es reemplazada y queda asi,
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">ugBM08</wsse:Password>
deberia quedar asi
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">ugBM08&#x2013;/Y~]&gt;</wsse:Password>

la cadena queda cortada por lo tanto los valores no van correctamente.

Si alguno a luchado con este problema de los caracteres especiales?.

Por ahora estoy intentando con esto pero no ayuda,
cPassword:= strtran( cPassword, '&', "& y" )

Muchas Gracias por la ayuda que e puedan enviar.

Saludos Mariano
mterraz
 
Posts: 54
Joined: Mon Jun 10, 2013 1:21 pm

Re: XML Caracteres Especiales

Postby karinha » Wed Aug 14, 2024 1:16 pm

Esto?

Code: Select all  Expand view

// C:\FWH\SAMPLES\MFERRAZ.PRG

#Include "FiveWin.ch"

FUNCTION Main()

   LOCAL cPassword, cVar

   cPassword := 'ugBM08&#x2013;/Y~]&gt;'

   cVar := TOMA_ACENTUACION( cPassword )

   ? cVar

RETURN NIL

FUNCTION TOMA_ACENTUACION( cStr )

   LOCAL cStrNew := "", nX, cAcentos, cLetras

   cAcentos := { "&","Ë", "œ", "‹", "‡", "A", "—", "ƒ", "Æ", "Ç", " ", "µ", "…", "·", "‚", "É", "ê", "ˆ", "", "Ò", "í", "Í", "ó", "¢", "à", "ä", "å", "“", "â", "ú", "é", "", "š", "ç", "€", "ã", "Ã", "á", "Á", "à", "À", "é", "É", "ê", "Ê", "í", "Í", "ó", "Ó", "õ", "Õ", "ô", "Ô", "ú", "Ú", "ü", "Ü", "ç", "ù", "AAO", "§", "¦", "º", "ª", "€", "‡", "Ç", "ç", "'", "`", "ø", "¡", "Þ", "×", "Ø", "ÿ", "Ö", chr( 239 ) }
   cLetras  := { "E","E", "Y", "I", "C", "A", "U", "A", "A", "A", "A", "A", "A", "A", "E", "E", "E", "E", "E", "E", "I", "I", "O", "O", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C", "C", "A", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "O", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C", " ", "AAO", ".", ".", ".", ".", "C", "C", "C", "C", "" , "" , ".", "I", "I", "I", "I", "", "I",  ""   }

   FOR nX := 1 TO LEN( cAcentos )

      cStrNew := StrTran( cStr, cAcentos[nX], cLetras[nX] )

      cStr := cStrNew

   NEXT

Return( cStrNew )

// FIN / END
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: XML Caracteres Especiales

Postby acuellar » Wed Aug 14, 2024 1:18 pm

Estimado Mariano

Intenta así:
Code: Select all  Expand view

cPassword:= strtran( cPassword, '&', "&amp;")
 


En éste link podés ver los otros
https://ascii.cl/es/codigos-html.htm
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1643
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: XML Caracteres Especiales

Postby Antonio Linares » Wed Aug 14, 2024 1:28 pm

Prueba si te funciona así:

Code: Select all  Expand view
PROCEDURE Main()
   LOCAL cPassword := 'ugBM08&#x2013;/Y~]>'
   LOCAL cEscapedPassword := EscapeXMLPassword(cPassword)
   LOCAL cXMLElement := '<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' + cEscapedPassword + '</wsse:Password>'

   ? "Contraseña original:", cPassword
   ? "Contraseña escapada:", cEscapedPassword
   ? "Elemento XML completo:", cXMLElement

RETURN

FUNCTION EscapeXMLPassword(cPassword)
   LOCAL cResult := ""
   LOCAL nLen := Len(cPassword)
   LOCAL cChar
   LOCAL i

   FOR i := 1 TO nLen
      cChar := SubStr(cPassword, i, 1)
      DO CASE
         CASE cChar == "&"
            cResult += "&amp;"
         CASE cChar == "<"
            cResult += "&lt;"
         CASE cChar == ">"
            cResult += "&gt;"
         CASE cChar == '"'
            cResult += "&quot;"
         CASE cChar == "'"
            cResult += "&apos;"
         OTHERWISE
            cResult += cChar
      ENDCASE
   NEXT

RETURN cResult
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: XML Caracteres Especiales

Postby mterraz » Wed Aug 14, 2024 2:04 pm

Son unos genios!! muchas gracias por la ayuda estoy implementado la solución que me compartieron y verificar los resultados.
Muchas gracias son colegas de primera!!!
Abrazo Mariano.
mterraz
 
Posts: 54
Joined: Mon Jun 10, 2013 1:21 pm


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 69 guests