Problema com JDOM + String com Acento

2 respostas
F

tenho o seguinte codigo trabalhando com XML e JDOM:

String pastaOrig = “C:\Teste”;

Element pastaOrigElement = new Element(pastaOrig);

pastaOrigElement.addContent(pastaOrig);

configElement.addContent(pastaOrigElement);

Dessa forma quando gravo meu XML funciona, mas se eu trocar a pasta de origem para uma que tenha acento no nome o XML é gerado errado, o arquivo nem abre corretamente.

Alguém sabe como resolver esse erro do JDOM? Ou estou fazendo algo errado?

2 Respostas

T

org.jdom.output.XMLOutputter

Dê uma olhada no Javadoc, basicamente ele diz que você deve especificar um “encoding” (no seu caso deve ser “ISO-8859-1”.)

Warning: When outputting to a Writer, make sure the writer's encoding matches the encoding setting in the Format object. This ensures the encoding in which the content is written (controlled by the Writer configuration) matches the encoding placed in the document's XML declaration (controlled by the XMLOutputter). Because a Writer cannot be queried for its encoding, the information must be passed to the Format manually in its constructor or via the Format.setEncoding(java.lang.String) method. The default encoding is UTF-8.
F

funcionou.

valew…

Criado 14 de julho de 2005
Ultima resposta 14 de jul. de 2005
Respostas 2
Participantes 2