title: JAXB to unmarshall <string>foobar</string>
body: <p>Greetings! I have a server returning XML content to my client that looks like this:</p>
  
  <pre><code>&lt;string xmlns="..."&gt;foobar&lt;/string&gt;
  </code></pre>
  
  <p>I'm new to JAXB and have gotten a lot of stuff working, except this. I thought it would be pretty easy to marshal and unmarshal this to and from a String. It took a while, but I finally figured out how to marshal this as</p>
  
  <pre><code>    public static String ToXML(String s) throws Exception
      {
          JAXBContext context = JAXBContext.newInstance(String.class);
          Marshaller marshaller = context.createMarshaller();
          StringWriter sw = new StringWriter();
          marshaller.marshal(new JAXBElement(new QName("", "String"), String.class, s), sw);
  
          return sw.toString();
      }
  </code></pre>
  
  <p>So my question is, how to I unmarshal this? It cannot be annotated as a root element. I cannot use java.lang as the package to create a new instance of a JAXBContext (I get an ObjectFactory missing exception). </p>
  
  <p>Any wisdom to impart? This can't be that hard, right?</p>