XML Unicode Problem

M

mosk

Gast
Hallo liebes Javaforum,

folgendes Problem:

Angenommen ich habe folgende XML Datei
Java:
<?xml version="1.0" encoding="UTF-8"?>
<node1>
	<node2>
		<name>test1</name>
		<node3>/</node3>
	</node2>
	<node2>
		<name>test2</name>
		<node3>/</node3>
	</node2>
</node1>

Jetzt habe ich ein Javaprogramm, welches mit von jeder node2 eine eigene Datei erzeugt und halt node2 inklusive Kinder in diese neu erzeugte Datei schreibt. Problem: der Inhalt aus node3 ist nicht mehr "/" sondern "\" (decodiert)!

Hier ist mein java-Code:

Java:
    private void debug() throws Exception {
        /*** Delete all existing .xml files: ***/
        deleteDirectory(path);
        
        SAXBuilder builder = new SAXBuilder();
        InputStream is = new FileInputStream(input);
        InputStreamReader isr = new InputStreamReader(is, "UTF-8");
        Reader in = new BufferedReader(isr);

        Document doc = builder.build(isr);

        //create a List containing all transformations
        Element elRoot = doc.getRootElement();
        listOfAllTransformations = elRoot.getChildren("node2");

        
        for (Element e : listOfAllTransformations) {
            String transName = e.getChild("name").getText();
            String transPath = e.getChild("node3").getText().equals("/") ? "" : e.getChild("node3").getText();
            System.out.println("node3: "+e.getChild("node3").getText());
            //create directories
            tmpTransformationPath = new File(path.getAbsolutePath() + transPath);
            tmpTransformationPath.mkdirs();

            //create xml file
            Element newRoot = (Element) e.clone();
            tmpTransformationDoc = new Document(newRoot);
            try {
                FileOutputStream fos = new FileOutputStream(path.getAbsolutePath() + transPath + "/" + transName + ".xml");
                Writer out = new OutputStreamWriter(fos, "UTF-8");
                XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setEncoding("UTF-8"));
                outputter.output(tmpTransformationDoc, out);
                fos.flush();
                fos.close();
            } catch (java.io.IOException exe) {
                exe.printStackTrace();
            }
        }
    }

Hat jemand eine Idee, woran das liegen kann? Vielen Dank im Voraus.
 
M

mosk

Gast
da ich nicht editieren kann, hier vllt noch gut zu wissen meine imports (benutze jDom):
Java:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.List;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.Document;
import org.jdom.output.XMLOutputter;
import org.jdom.output.Format;
Die Variaben path (wo die neu erzeugten Dateien gespeichert werden sollen) und input (die "große" xml file) sind vom Typ File.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
N JSON export String Unicode? XML & JSON 6
J JDOM Unicode XML & JSON 2
O XPATH Problem - Anfänger XML & JSON 4
so_ein_Komischer Problem mit Clean and Build XML & JSON 1
P JAXB-Problem XML & JSON 1
W Problem mit dem mit XML sortierung XML & JSON 2
S Jaxb Unmarshalling Problem XML & JSON 4
E einfaches Problem XML + XSD + jedit XML & JSON 2
S Xslt Problem XML & JSON 2
B JasperReport Problem in Runtime XML & JSON 2
S Problem with JAXB unmarshalling classes that have the same name in @XmlRootElement XML & JSON 2
R Problem bei: XML und XSL zu HTML XML & JSON 2
M Read / write Problem beim ByteStrom XML & JSON 2
M XML write Problem zweiter Ansatz XML & JSON 3
M XML read Problem XML & JSON 4
M XML write Problem XML & JSON 2
whitenexx Problem beim parsen von Facebook XML XML & JSON 3
S XJC --> Java-Objects compile Problem XML & JSON 4
F XPath-Problem mit DOM4J XML & JSON 8
B JPA + JAXB Mapping Problem XML & JSON 2
T XPath Problem: finden einer Node nach Attributswert XML & JSON 2
G Problem beim schreiben von XML in eine File XML & JSON 2
S Encoding Problem XML & JSON 7
K JAXB und Maps -> Marshalling-Problem XML & JSON 6
B Problem beim löschen von ChildNodes aus einem XML-DOM XML & JSON 3
E JDOM - Problem beim Zusammenfügen zweier Dateien XML & JSON 2
M JExcelAPI (JXL) Encoding Problem XML & JSON 11
S DOM Parsen Problem mit HTML Sonderzeichen XML & JSON 4
A aus xml --> html Problem XML & JSON 3
Y stax Problem XML & JSON 3
slawaweis Problem mit XSLT (wahrscheinlich ein Bug in Java 6) XML & JSON 16
T Problem beim Parsen von Attribut xmlns="urn:com:test&qu XML & JSON 6
P XPath Problem XML & JSON 2
J Problem beim XML-Lesen XML & JSON 2
M Problem mit FOP in Java Programm XML & JSON 2
S Problem mit XPath XML & JSON 4
J Problem mit compile einer XSD XML & JSON 3
N jdom problem beim lesen von child elementen XML & JSON 5
N problem bei xml lesen mit jdom XML & JSON 2
A XPath Problem XML & JSON 2
W JDOM element ändern funzt nich :( [problem gelöst] XML & JSON 3
G Problem mit XML-Schema Validierung mit Java XML & JSON 12
B jdom: getChildren() problem XML & JSON 4
H XSL-FO Problem mit If XML & JSON 2
loadbrain XPath Problem XML & JSON 2
T addContent / Problem mit Variable XML & JSON 2
F Problem mit JAXB Unmarshaller XML & JSON 2
F JDOM und XPath - Problem mit Namespace ohne Prefix XML & JSON 5
8 SAXParser Problem, startElement wird nicht ausgeführt XML & JSON 2
M Java und XSLT: Performanz-Problem XML & JSON 5
X JDOM SAXBuilder Validationschema - Problem XML & JSON 8
G Problem mit getContent XML & JSON 4
K stax problem XML & JSON 2
S Problem mit SAX XML & JSON 6
A Problem mit JasperReport XML & JSON 6
G DOCTYPE Problem beim Transformer/TransformerFactory etc. XML & JSON 13
C XSD Problem XML & JSON 16
R Problem bei Erstellung von XML(JDOM) XML & JSON 3
R Problem mit SAX-Parser characters() XML & JSON 7
M XPath Problem im Zusammenhang mit document() XML & JSON 2
P Problem beim erstellen eines neuen Elements (JDOM) XML & JSON 5
Z Problem mit getNodeValue() und setNodeValue() in DOM XML & JSON 6
H JAXB CUSTOMIZATION PROBLEM XML & JSON 2
M XPATH und RSS (Problem namespaces) XML & JSON 7
P SAXParser problem? XML & JSON 2
S Problem beim Erstellen eines pdfs XML & JSON 3
V Problem mit xsd XML & JSON 2
P XML mit hilfe von JDOM abspeichern macht Problem XML & JSON 6
G Problem mit addContent() XML & JSON 4
B DTD Problem - Reihenfolge der Einträge XML & JSON 2
R Problem beim Auslesen von Attributen XML & JSON 4
K Problem mit ant/java web services XML & JSON 4
K xml Datei mit JDOM erzeugen, Problem Namespaces XML & JSON 1
P Problem mit XML und DOM XML & JSON 2

Ähnliche Java Themen

Neue Themen


Oben