title: How to convert String to DOM Document object in java?
body: <p>I have a case like getting an XML and convert the XML elements to document object and getting the element values and attributes which i have been created already</p>
  
  <p>Here is the piece of code i have tried to convert the string to DOM document object</p>
  
  <pre><code>String xmlString = " &lt;r&gt;&lt;e&gt;d&lt;/e&gt;&lt;/r&gt;";
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder = factory.newDocumentBuilder();
  org.w3c.dom.Document document = builder.parse(new InputSource(new StringReader(xmlString)));    
  TransformerFactory transformerFactory = TransformerFactory.newInstance(); 
  Transformer transformer = transformerFactory.newTransformer();
  DOMSource source = new DOMSource(document);
  StreamResult result =  new StreamResult(new StringWriter());
  transformer.transform(source, result);
  String str1 = result.getWriter().toString();
  System.out.println(str1);
  </code></pre>
  
  <p>But this case is valid for only elements without attributes
  what can we do if the </p>
  
  <pre><code>String xmlString = "&lt;element attribname="value" attribname1="value1"&gt; pcdata&lt;/element&gt;"
  </code></pre>
  
  <p>we are using Double quotes for the attribute values"value". The compiler is showing error</p>
  
  <p>Suggest me if there any xml encoder and decoder is there to handle this scenarios ??</p>