Convert XML into UTF-8 to ISO-8859-1

2

I am developing a web service that is invoked by an application external to mine. In this web service I receive an XML with all the necessary parameters to offer the service. The issue is that the XML comes with UTF-8 encoding and the database where the information is stored is in Latin 1 (ISO-8859-1). How can I convert the XML to Latin 1 encoding? Either the full XML or the attributes once extracted. I have a Java class that implements the object that is received.

Example: I have the object visita and it has an attribute that is visita.getComentarioS() . To get the object from the XML I do the following:

XmlVisita visita = (XmlVisita ) context.getParameter("xmlVisita");

where context is an object of type EventHandlerContext . When storing the comment of the visit in the database, if it contains special characters, it is stored badly since the database is in Latin 1.

    
asked by MrSman 04.09.2018 в 13:33
source

1 answer

0

I would try with XSLT , to change the header to encoding="ISO-8859-1" :

<xsl:output encoding="ISO-8859-1"/>

I have not tried it but it would be something like that, try it and you already edit your answer:

TransFormerFactory tFactory = TransformerFactory.newInstance();
Source xsl = new StreamSource("../doc.xsl");
Source xml = new StreamSource("../doc.xml");
Result salida = new StreamResult(new File("newDoc.xml"));
Transformer transformer = tFactory.newTransformer(xsl);
transformer.transform(xml,salida);

Greetings.

    
answered by 04.09.2018 в 15:21