XML Caracteres Especiales

Post Reply
mterraz
Posts: 54
Joined: Mon Jun 10, 2013 1:21 pm

XML Caracteres Especiales

Post by mterraz »

Estimados me encuentro con un problema con _ especiales dentro de un XML. No puedo encontrar una forma efectiva de que _ 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–/Y~]></wsse:Password>

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

Si alguno a luchado con este problema de _ 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
User avatar
karinha
Posts: 7885
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Contact:

Re: XML Caracteres Especiales

Post by karinha »

Esto?

Code: Select all | Expand

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

#Include "FiveWin.ch"

FUNCTION Main()

   LOCAL cPassword, cVar

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

   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
acuellar
Posts: 1645
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: XML Caracteres Especiales

Post by acuellar »

Estimado Mariano

Intenta así:

Code: Select all | Expand

cPassword:= strtran( cPassword, '&', "&")
 
En éste link podés ver los otros
https://ascii.cl/es/codigos-html.htm
Saludos,

Adhemar C.
User avatar
Antonio Linares
Site Admin
Posts: 42259
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: XML Caracteres Especiales

Post by Antonio Linares »

Prueba si te funciona así:

Code: Select all | Expand

PROCEDURE Main()
   LOCAL cPassword := 'ugBM08–/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 += "&"
         CASE cChar == "<"
            cResult += "<"
         CASE cChar == ">"
            cResult += ">"
         CASE cChar == '"'
            cResult += """
         CASE cChar == "'"
            cResult += "&apos;"
         OTHERWISE
            cResult += cChar
      ENDCASE
   NEXT

RETURN cResult
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
mterraz
Posts: 54
Joined: Mon Jun 10, 2013 1:21 pm

Re: XML Caracteres Especiales

Post by mterraz »

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.
Post Reply