title: How to create a XML object from String in Java?
body: <p>I am trying to write a code that helps me to create a XML object. For example, I will give a string as input to a function and it will return me a XMLObject.</p>
  
  <pre><code>XMLObject convertToXML(String s) {}
  </code></pre>
  
  <p>When I was searching on the net, generally I saw examples about creating XML documents. So all the things I saw about creating an XML and write on to a file and create the file. But I have done something like that:</p>
  
  <pre><code>Document document = new Document();
  Element child = new Element("snmp");
  child.addContent(new Element("snmpType").setText("snmpget"));
  child.addContent(new Element("IpAdress").setText("127.0.0.1"));
  child.addContent(new Element("OID").setText("1.3.6.1.2.1.1.3.0"));
  document.setContent(child);
  </code></pre>
  
  <p>Do you think it is enough to create an XML object? and also can you please help me how to get data from XML? For example, how can I get the <code>IpAdress</code>from that XML?</p>
  
  <p>Thank you all a lot</p>
  
  <p><strong>EDIT 1:</strong> Actually now I thought that maybe it would be much easier for me to have a file like <code>base.xml</code>, I will write all basic things into that for example:</p>
  
  <pre><code>&lt;snmp&gt;
  &lt;snmpType&gt;&lt;snmpType&gt;
  &lt;OID&gt;&lt;/OID&gt;
  &lt;/snmp&gt;
  </code></pre>
  
  <p>and then use this file to create a XML object. What do you think about that? </p>