I have this function in my code base, this should work for you.
public static Document loadXMLFromString(String xml) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(xml)); return builder.parse(is); }
also see this similar question
Related Posts:
- How to convert/parse from String to char in java?
- “Content is not allowed in prolog” when parsing perfectly valid XML on GAE
- What is the best/simplest way to read in an XML file in Java application?
- How do I convert a String to an int in Java?
- How to format strings in Java
- Java – Convert integer to string [duplicate]
- How to split a string in Java
- How do I compare strings in Java?
- How to convert a char to a String?
- Reverse a string in Java
- How to parse JSON in Java
- Reverse a string in Java
- Java String Split by “|”
- Convert String to double in Java
- Java String new line
- How to check if a String contains another String in a case insensitive manner in Java?
- Java split string to array [duplicate]
- String concatenation: concat() vs “+” operator
- How to remove the last character from a string?
- Error parsing data org.json.JSONException: Value
- Java string to date conversion
- How to replace � in a string
- Change date format in a Java string
- What are all the escape characters?
- Converting String to “Character” array in Java
- Best way to convert an ArrayList to a string
- Best way to convert an ArrayList to a string
- How to split a String by space
- String interpolation in Java 14 or 15
- What is Parse/parsing?
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- How to remove single character from a String
- How to parse this string in Java?
- How to convert any Object to String?
- How to split a string in Java
- Which HTML Parser is the best?
- How do I save a String to a text file using Java?
- Illegal Escape Character “\”
- Can I multiply strings in Java to repeat sequences?
- What does regular expression \\s*,\\s* do?
- How to convert a Binary String to a base 10 integer in Java
- Left Hand Side of an Assignment must be a Variable CharAt
- How to capitalize the first letter of a String in Java?
- catDog string problem at Codingbat.com
- Java way to check if a string is palindrome
- Return string Input with parse.string
- What is the difference between String.subString() and String.subSequence()
- How do I apply the for-each loop to every character in a String?
- Java – removing first character of a string
- Java compressing Strings
- Explain the use of a bit vector for determining if all characters are unique
- Explain the use of a bit vector for determining if all characters are unique
- Convert array of strings into a string in Java
- How to parse JSON in Java
- Sort a single String in Java
- How to remove single character from a String
- How to remove single character from a String
- What is Java String interning?
- What is Java String interning?
- What is Java String interning?
- Rename a file using Java
- Why is there no String.Empty in Java?
- Java split string to array
- Using Enum values as String literals
- What is the easiest/best/most correct way to iterate through the characters of a string in Java?
- The system cannot find the file specified in java
- int cannot be converted to string?
- How to check if my string is equal to null?
- what is Ljava.lang.String;@
- Converting JSON to XML in Java
- Convert String to int array in java
- align text center with android
- Converting String Array to an Integer Array
- How to read json file into java with simple JSON library
- How to sort an array of objects in Java?
- How to sort an array of objects in Java?
- How to compress a String in Java?
- java.lang.NumberFormatException: empty String
- How to check if a String is numeric in Java
- How to replace a substring of a string
- Converting A String To Hexadecimal In Java
- javax.xml.bind.UnmarshalException: unexpected element (uri:””, local:”Group”)
- Immutable class?
- org.xml.sax.SAXParseException: Content is not allowed in prolog
- Java can’t find file when running through Eclipse
- Converting a string to an integer on Android
- HTTP Status 500 Error instantiating servlet class
- Simple way to repeat a string
- Java end of file
- Unclosed Character Literal error
- Java: how to initialize String[]?
- Regular Expressions on Punctuation
- Add String Array to ArrayList
- StringIndexOutOfBoundsException String index out of range: 0
- How to extract a substring using regex
- Invalid escape sequence (valid ones are \b \t \n \f \r \” \’ \\ )
- How to read and write XML files?
- difference between equals() and hashCode()
- How can I check if a single character appears in a string?
- Difference between String replace() and replaceAll()