Use the (excellent) JSON-Java library from json.org then
JSONObject json = new JSONObject(str); String xml = XML.toString(json);
toString
can take a second argument to provide the name of the XML root node.
This library is also able to convert XML to JSON using XML.toJSONObject(java.lang.String string)
Check the Javadoc
Link to the the github repository
POM
<dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20160212</version> </dependency>
original post updated with new links
Related Posts:
- How to parse JSON in Java
- “Content is not allowed in prolog” when parsing perfectly valid XML on GAE
- No String-argument constructor/factory method to deserialize from String value (”)
- How to send a Map in JSON
- A message body writer for Java class java.util.ArrayList and MIME media type application/json was not found
- What is the best/simplest way to read in an XML file in Java application?
- How to parse JSON in Java
- How to parse JSON boolean value?
- Only using @JsonIgnore during serialization, but not deserialization
- align text center with android
- How to read json file into java with simple JSON library
- Simplest way to read JSON from a URL in Java
- javax.xml.bind.UnmarshalException: unexpected element (uri:””, local:”Group”)
- org.xml.sax.SAXParseException: Content is not allowed in prolog
- HTTP Status 500 Error instantiating servlet class
- How to convert the following json string to java object?
- How to create JSON Object using String?
- How to read and write XML files?
- How to Get JSON Array Within JSON Object?
- How to upload a file and JSON data in Postman?
- Cannot resolve symbol ‘button’ -Android Studio
- Jackson with JSON: Unrecognized field, not marked as ignorable
- JsonMappingException: No suitable constructor found for type [simple type, class ]: can not instantiate from JSON object
- How to easily convert a BufferedReader to a String?
- package org.json does not exist when importing org.json.JSONObject
- Parsing JSON string in Java
- Error: The processing instruction target matching “[xX][mM][lL]” is not allowed
- android.content.res.Resources$NotFoundException: String resource ID #0x0
- How to set menu to Toolbar in Android
- Http status 401 This request requires HTTP authentication (). in tomcat 6
- Android Studio 2.2.3: Gradle project sync failed. Basic functionality (e.g. editting, debugging) will not work properly
- In Java, how do I parse XML as a String instead of a file?
- No content to map due to end-of-input jackson parser
- How to format strings in Java
- What exactly is Apache Camel?
- What is an instance variable in Java?
- How does the Java ‘for each’ loop work?
- Cannot make a static reference to the non-static method fxn(int) from the type Two
- How to implement a tree data-structure in Java?
- Difference between StringBuilder and StringBuffer
- How can I use pointers in Java?
- How do I generate random integers within a specific range in Java?
- How to remove single character from a String
- Unsupported major.minor version 52.0 [duplicate]
- How do I limit the number of decimals printed for a double?
- Unfortunately MyApp has stopped. How can I solve this?
- exception in thread ‘main’ java.lang.NoClassDefFoundError:
- java.io.FileNotFoundException: the system cannot find the file specified
- How to parse this string in Java?
- Service will not start: error 1067: the process terminated unexpectedly
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- Explain the use of a bit vector for determining if all characters are unique
- Convert java.util.Date to String
- How do I do a deep copy of a 2d array in Java?
- Returning an empty array
- Java Security: Illegal key size or default parameters?
- Could not reserve enough space for object heap
- What is the difference between a local variable, an instance field, an input parameter, and a class field?
- Error: Selection does not contain a main type
- Java, “Variable name” cannot be resolved to a variable
- JRE 1.7 – java version – returns: java/lang/NoClassDefFoundError: java/lang/Object
- Good Java graph algorithm library?
- Integrate Ant builder into Eclipse: Error “Variable references empty selection”
- local variables referenced from an inner class must be final or effectively final
- java.lang.NumberFormatException: empty String
- Java and Windows – error: illegal escape character
- How should I copy Strings in Java?
- Bank Account Java Program
- List of all special characters that need to be escaped in a regex
- No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
- java.lang.ArithmeticException: / by zero
- Eclipse error, “The selection cannot be launched, and there are no recent launches”
- STS launch error – Java was started but returned exit code=13
- RecyclerView onClick
- Java, Shifting Elements in an Array
- error: bad operand types for binary operator ‘&&’
- Exception in thread “main” java.lang.ArithmeticException: / by zero
- Failed to load the JNI shared Library (JDK)
- How to write an ArrayList of Strings into a text file?
- how to fix Cannot call sendRedirect() after the response has been committed?
- Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
- difference between equals() and hashCode()
- Adding days to a date in Java
- The C# Shorthand getters and setters
- What’s the reason I can’t create generic array types in Java?
- How to pass an object from one activity to another on Android
- Finding the size of a char array in Java
- When/why to call System.out.flush() in Java
- Throwing multiple exceptions in Java
- fixing errors on a program to call methods in java
- How to Set the Background Color of a JButton on the Mac OS
- How can I calculate a time difference in Java?
- Detecting a long press with Android
- How to increase the size of an array in Java?
- Split string into array of character strings
- intellij idea – Error: java: invalid source release 1.9
- How fix Error:java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:
- Is it okay to throw NullPointerException programmatically?
- Android: how to create Switch case from this?
- Read next word in java