title: Creating OpenSAML Assertion from given XML in Java
body: <p>I have been beating my head against this for a while, and am starting to make progress. However, I ran into some trouble converting a string representation of a SAML 2 Assertion (in XML) to an Assertion object.</p>
  
  <p>It looks like I am getting a valid <code>org.w3c.dom.Document</code> with appropriate data, and I seem to be getting a valid <code>SAMLObjectBuilder&lt;Assertion&gt;</code> from the builder factory, but when I try to put them together all I get is a blank Assertion; subject, issuer, issue time and so on are all <code>null</code>, despite them clearly being set in the XML.</p>
  
  <p>Does anyone see what I am doing wrong, and can suggest a solution?</p>
  
  <pre><code>Document doc = loadXMLFromString(saml);
  
  XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
  
  SAMLObjectBuilder&lt;Assertion&gt; assertionBuilder =
    (SAMLObjectBuilder&lt;Assertion&gt;)
    builderFactory.getBuilder(Assertion.DEFAULT_ELEMENT_NAME);
  
  Assertion assertion = assertionBuilder.buildObject(doc.getDocumentElement());
  
  String nameID = assertion.getSubject().getNameID().getValue();
  </code></pre>
  
  <p>At the nameID assignment, <code>assertion.getSubject()</code> returns <code>null</code>, failing the remainder of the expression.</p>
  
  <p>The example I am using is the full XML from sstc-saml-tech-overview-2.0-draft-03, page 10.</p>
  
  <p>The function <code>loadXMLFromString()</code> above is mostly borrowed from <a href="https://stackoverflow.com/questions/562160/in-java-how-do-i-parse-xml-as-a-string-instead-of-a-file/562207#562207">In Java, how do I parse XML as a String instead of a file?</a></p>