Hello,
iam doing program , that need to convert xml file into string ,
this program just read the xml file , but doesn't convert it to string, coz i don't know how to do it!, some one could teach me how?
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class example
{
public static void main( String[] args )
{
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("file.xml");
try{
Document document = (Document) builder.build(xmlFile);
Element rootNode = document.getRootElement();
List list = rootNode.getChildren("info");
for (int i=0; i< list.size(); i++)
{
Element node = (Element) list.get(i);
System.out.println("name : " + node.getChildText("name"));
System.out.println("city : " + node.getChildText("city"));
System.out.println("age : " + node.getChildText("age"));
}
}catch(IOException io){
System.out.println(io.getMessage());
}catch(JDOMException jdomex){
System.out.println(jdomex.getMessage());
}
}
}
and the xml file
<?xml version="1.0"?>
<data>
<info>
<name>Tom</name>
<city>London</city>
<age>40</age>
</info>
<info>
<name>Michael</name>
<city>Berlin</city>
<age>50</age>
</info>
<info>
<name>Raphael</name>
<city>Paris</city>
<age>54</age>
</info>
</data>