I want to convert a String to org.jdom.Element
String s = "<rdf:Description rdf:about=\"http://dbpedia.org/resource/Barack_Obama\">";
How can I do it?
I want to convert a String to org.jdom.Element
String s = "<rdf:Description rdf:about=\"http://dbpedia.org/resource/Barack_Obama\">";
How can I do it?
 
    
     
    
    There is more than one way to parse XML from string:
  String xml = "Your XML";
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  DocumentBuilder db = dbf.newDocumentBuilder();
  Document doc = db.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));     
Using a SAXParser which can read an inputsource:
 SAXParserFactory factory = SAXParserFactory.newInstance();
 SAXParser saxParser = factory.newSAXParser();
 DefaultHandler handler = new DefaultHandler() {
 saxParser.parse(new InputSource(new StringReader("Your XML")), handler);    
See: SAXParser, InputSource
 
    
     
    
    Document from your string. Look at JDOM FAQ: How do I construct a Document from a String?Document.getRootElement() to access the root element.(You mentioned package org.jdom so I assume you work with JDOM 1.1.)
 
    
    I recommend you use the Simple XML Framework from http://simple.sourceforge.net/.With this framework you can serialize and deserialize your objects easily. I hope this information can be important for you.
