File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes xml-josn object or string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xml-josn object or string" Watch "xml-josn object or string" New topic
Author

xml-josn object or string

jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
hi. please any body suggest me how to convert xml file to json object.
any process please urgent
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

As for "urgent", please read this: EaseUp.

Let me point out that there are XML documents which can't be expressed as JSON documents. XML is just more complex than JSON is. But having said that, the way I would approach this would be to use the google keywords "xml convert json" and see what turns up.

Or did you already try that? What did you try so far?
jyothsna ananthula
Ranch Hand

Joined: Jun 02, 2011
Posts: 33
Paul Clapham wrote:As for "urgent", please read this: EaseUp.

Let me point out that there are XML documents which can't be expressed as JSON documents. XML is just more complex than JSON is. But having said that, the way I would approach this would be to use the google keywords "xml convert json" and see what turns up.

Or did you already try that? What did you try so far?



yes i tried in google with xml-json and xml file to convert to json.

i developed the following code, in this i am unable to find the jars what ever needed for this application.and could you please suggest me for example org.json.XML is one package so for if use this package methods in class getting error.so i came to know jar is not available.but what type of jar i need to download.for this i came to know to download json-org jar.please let me know how to know jar needed for particular application.

import java.io.*;


import net.sf.json.JSONObject;
import net.sf.json.xml.XMLSerializer;
import org.apache.commons.io.IOUtils;
import net.sf.json.JSON;






class ConvertToJsonObject {

public static void main(String[] args) throws IOException{

InputStream file1 = new FileInputStream(new File("C:\\Documents and Settings\\JA0084604\\Desktop\\NMS\\XO-OpenNMS\\build.xml"));


try {
JSONObject xmlJSONObj=new JSONObject();

xmlJSONObj = XML.toJSONObject(file1);
String jsonPrettyPrintString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);

System.out.println(jsonPrettyPrintString);
} catch (JSONException je) {
System.out.println(je.toString());
}
}}

/* String xml = IOUtils.toString(file1);

JSONObject xmlJSONObj=new JSONObject();

XMLSerializer xmlSerializer = new XMLSerializer();


JSON json= xmlSerializer.read(xml);
System.out.println( json.toString(2) );


}*/

paul please help me in the following program

import java.io.*;


import net.sf.json.JSONObject;
import net.sf.json.xml.XMLSerializer;
import org.apache.commons.io.IOUtils;

import org.json.XML;






class ConvertToJsonObject {

public static void main(String[] args) throws IOException{

InputStream file1 = new FileInputStream(new File("C:\\Documents and Settings\\JA0084604\\Desktop\\NMS\\XO-OpenNMS\\build.xml"));

String xml = IOUtils.toString(file1);
try {
JSONObject xmlJSONObj=new JSONObject();

xmlJSONObj = XML.toJSONObject(xml); // in this line error getting as required net.sf.json.JSONObject found org.json.josn object
String jsonPrettyPrintString = xmlJSONObj.toString(2);

System.out.println(jsonPrettyPrintString);
} catch (JSONException je) {
System.out.println(je.toString());
}
}}


please help me how to resolve


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xml-josn object or string