Firstly, as others have stated, you shouldn't use any XML processing. Just read the file as a text file.

Secondly, your umlaut characters showing up as '�' is due to an incorrect charset (encoding) being used. The charset error may be in your code, or it may be the XML file.

The original XML file contains encoding="windows-1252", but it's unusual for XML to be encoded in anything other than UTF-8, so I suspect the file is really a UTF-8 file and the encoding it claims to use is not correct.

Try forcing UTF-8 when reading the file. It's good practice, regardless, to specify the charset when converting bytes to text:

String xml = new String(
    Files.readAllBytes(xmlFile.toPath(), StandardCharsets.UTF_8));
Answer from VGR on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java string › convert an xml object to a string in java
Convert an XML Object to a String in Java | Baeldung
June 20, 2025 - In this tutorial, we’ll discuss several ways of transforming an XML Document object into a string in Java. ... Document document = // ... This Document object represents XML content in memory: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <root> <child1>This is child element 1</child1> <child2>This is child element 2</child2> </root> Now, we need to convert this XML Document object into a Java string.
Discussions

java - XML Document to String - Stack Overflow
What's the simplest way to get the String representation of a XML Document (org.w3c.dom.Document)? That is all nodes will be on a single line. As an example, from trge More on stackoverflow.com
🌐 stackoverflow.com
java convert string to xml and parse node - Stack Overflow
Hello I am getting back a string from a webservice. I need to parse this string and get the text in error message? My string looks like this: -2 More on stackoverflow.com
🌐 stackoverflow.com
I created an XML Strings Translator Tool
I don't specifically need that XML translator, but - assuming the other sites like Mb2Kb, reddit downloader etc are yours, then I gotta say they are really cool and not bloated. I was shocked that in days of cloud computing there are image manipulation websites which legit work offline More on reddit.com
🌐 r/androiddev
52
39
May 22, 2024
How to convert a String into XmlString in Java 7
I would suggest, instead of working with string, unmarshall your xml response into an object. Something like: https://www.javaguides.net/2018/10/how-to-convert-xml-to-java-object-jaxb-unmarshalling.html?m=1 In real life you almoust never work with string response body. More on reddit.com
🌐 r/javahelp
3
0
May 27, 2025
🌐
Oracle
forums.oracle.com › ords › apexds › post › how-to-parse-whole-xml-elements-into-a-java-string-0709
how to parse whole xml elements into a java String - Oracle Forums
January 17, 2008 - hello everybody, I am trying to parse whole xml into a string for example my xml file is as below: ---------------------------------
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-convert-string-to-xml-document-and-xml-document-to-string
Java Convert String to XML Document and XML Document to String | DigitalOcean
August 3, 2022 - String convertDocumentToString(Document doc): This method will take input as Document and convert it to String. We will use Transformer, StringWriter and StreamResult for this purpose. package com.journaldev.xml; import java.io.StringReader; import java.io.StringWriter; import javax.xml.pa...
🌐
Json2CSharp
json2csharp.com › code-converters › xml-to-java
Convert XML to JAVA Object Online - Json2CSharp Toolkit
When you copy the returned classes in the directory of your solution, you can deserialize your XML string or file using the 'Root' class as mentioned in commented example below: Here are the classes returned from the previous example: public class additionalCosts { public String value; public String currency; public String marketingType; public String priceIntervalType; } public class realestates { public String externalId; public String title; public String creationDate; public String lastModificationDate; public String thermalCharacteristic; public String energyConsumptionContainsWarmWater; public String buildingEnergyRatingType; public String additionalArea; public String numberOfFloors; public additionalCosts additionalCosts; }
🌐
Blogger
javarevisited.blogspot.com › 2015 › 07 › how-to-read-xml-file-as-string-in-java-example.html
How to Read XML File as String in Java? 3 Examples
May 16, 2023 - Since an XML file is also a file, you can use BufferedReader or FileInputStream to read the content of an XML file as String by using the techniques, I have discussed in my earlier post 3 ways to convert InputStream to String in Java.
Find elsewhere
🌐
ServiceNow Community
servicenow.com › community › developer-forum › how-do-i-convert-xml-object-to-string-requirement-is-to-replace › m-p › 2093269
How do I convert XML object to String ? Requirement is: to replace < and > with < and > respectively and make the string back to XML format. Sample XML is shown as below.
June 11, 2018 - var xmlString = responseBody.toString(); var xmlClean = global.JSUtil.unescapeText(xmlString); JSUtils is an OOB Script Include already present in every instance. ... ServiceNow Runbook Template: Best Practices for Reliable Deployments in Developer articles yesterday · ServiceNow Integration Tutorial: How Integrations Really Work (Step-by-Step) in Developer articles yesterday · How to make variable mandatory based task field conditions.
🌐
Mkyong
mkyong.com › home › java › java – convert string to xml
Java - Convert String to XML - Mkyong.com
July 29, 2022 - This article shows how to convert a String to an XML document and an XML document back to a String in Java, using DOM parser and JDOM2 parser.
🌐
Coderanch
coderanch.com › t › 129379 › languages › converting-xml-java-objects
converting xml to java objects (XML forum at Coderanch)
So this part is called Marshalling. and I know you are asking about 'unmarshalling' and I couldnt find a better sample example on the web to give you a link but I did work on this part and I may be able to help you with that... first get familiarize with the xjc stuff from above link (generating java objects from the schema) and see the above example (marshalling) and unmarshalling will be very simple. just other way around to marshalling example. here is some sample code I wrote .. in the above code, "generatedLogResultInputValues" is the directory of the java classes which are generated by XSD. and "logXMLstr" is the XML string that I am trying to convert into the Java objects...
🌐
Plan
saxonica.plan.io › boards › 3 › topics › 4241
Passing XML as a String Parameter - Saxon - Saxonica Developer Community - Saxon - Saxonica Developer Community - Saxon - Saxonica Developer Community
The simplest is probably to pass the parameter as a StreamSource: String xml = "<x>the xml</x>"; StringReader sr = new StringReader(xml); StreamSource ss = new StreamSource(sr); transformer.setParameter(name, ss); Alternatively you can use saxon:parse() to parse the XML once it arrives in the ...
🌐
Java Code Geeks
javacodegeeks.com › home › core java
How to Parse XML from a String in Java - Java Code Geeks
November 18, 2024 - In this example, the ByteArrayInputStream converts the String into bytes and wraps it in a stream, which is then passed to the DocumentBuilder. The DocumentBuilder.parse() method reads the InputStream and generates a DOM Document. InputSource: Use when working with small, well-defined XML strings and you want a straightforward solution. InputStream: Use when encoding is critical or when the XML string is generated from byte-based sources. In this article, we explored two effective methods for parsing XML from a String in Java: using an InputSource with a StringReader and converting the String into an InputStream.
🌐
Baeldung
baeldung.com › home › java › java string › parse xml as a string in java
Parse XML as a String in Java | Baeldung
August 15, 2025 - In this tutorial, we’ll discuss how to convert an XML string to an XML document. In particular, we’ll cover two approaches to the problem. Then, we’ll discuss how to parse an XML file into a Java String object.
🌐
Coderanch
coderanch.com › t › 224295 › java › return-XML-data-string
How to return XML data as a string? (Web Services forum at Coderanch)
I'm currently using JDeveloper and having it create the WSDL based on my java class. The return type in WSDL is a simple "xsd:string" as I would expect. Because of this change from my literal character of '<' and '>' to the expanded xml notation, I am having problems consuming the response in client applications.
🌐
How to do in Java
howtodoinjava.com › home › java xml › java convert xml to string – write xml dom to a file
Java Convert XML to String - Write XML Dom to a File
March 9, 2023 - StringWriter writer = new StringWriter(); //transform document to string transformer.transform(new DOMSource(xmlDocument), new StreamResult(writer)); return writer.getBuffer().toString(); } catch (TransformerException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return null; } private static void writeXmlDocumentToFile(Document xmlDocument, String fileName) { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; try { transformer = tf.newTransformer(); //Uncomment if you do not require XML declaration //transformer.setOutputProperty(Outp
🌐
Coderanch
coderanch.com › t › 376659 › java › Parsing-XML-string-Java-Program
Parsing XML string using Java Program (Java in General forum at Coderanch)
I just want to parse the file manually. To do this i have converted the XML file to String using java io. Now i have to parse this String(contains XML) without using SAX or DOM.
🌐
How to do in Java
howtodoinjava.com › home › java xml › java convert string to xml dom example
Java Convert String to XML DOM Example
March 9, 2023 - To get the XML dom from XML file, instead of passing the XML string to DocumentBuilder, pass the file path to let the parser read the file content directly. We have employees.xml file which has XML content, we will read to get XML document. <employees> <employee id="101"> <name>Lokesh Gupta</name> <title>Author</title> </employee> <employee id="102"> <name>Brian Lara</name> <title>Cricketer</title> </employee> </employees> import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; public class StringtoXMLExample
🌐
Baeldung
baeldung.com › home › xml › convert string containing xml to org.w3c.dom.document
Convert String Containing XML to org.w3c.dom.Document | Baeldung
June 20, 2025 - This essential class represents an entire XML document and provides a comprehensive set of methods for navigating, modifying, and retrieving data from XML documents. When working with XML in Java, the org.w3c.dom.Document object becomes an indispensable tool. To better understand how to create an org.w3c.dom.Document object, let’s look at the following example:
🌐
SAP Community
community.sap.com › t5 › technology-q-a › xml-to-string-java-mapping › qaq-p › 9164380
Solved: XML to String Java Mapping - SAP Community
December 21, 2012 - The 'http://626_XIB.ProcesamientoMasivo/Esquema_AltaConvenios_SIBA_Entrada.xsd:TICU_Q40' element is invalid - The value '00000' is invalid according to its datatype 'String' - The actual length is greater than the MaxLength value. ... From your first post I can make out the source XML. Could you please provide the complete intended target XML after mapping. The output suggested in your first post is not the complete XML , I beleive the output is content of a field within the target XML. Java mapping needs complete target XML structure.