title: Data Source from string
body: <p>I'm wanting to use a args string that I'm passing into Java as a data source to fill my report. I have been attempting to create a JRXmlDataSource from the string to pass into fillreport. I've tried converting the string to a Doc, convert the string into a filestream, and just loading the string directly. I have even attempted to just create a file and load it in that way but nothing works. Any help would be appreciated. </p>
  
  <p>Main Method: </p>
  
  <pre><code>public class Testing {
  
      public static void main(String[] args) throws JRException {
          try {
              String xmlData = args[0];
              JasperReport jasperReport = null;
              String path = "C:/workspace/testProject/testing/sources/";
              JasperPrint jasperPrint = null;
  
              Document doc = convertStringToDocument(xmlData);
              JRXmlDataSource xmlDataSource = new JRXmlDataSource(doc);
  
              //Provide path for your JRXML template.
              String templateName = path + "report2.jrxml";
  
              //Provide path for your final pdf file.
              String destinationFile = path + "ReportSQL.pdf";
  
              //Compiling the template.
              jasperReport = JasperCompileManager.compileReport(templateName);
  
              //Sending a parameter with the logged in user name as value
              HashMap parameters = new HashMap();
  
              // Filling the report template with data
              jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, xmlDataSource);
  
              //Sending a Complete print of the report.
              JasperPrintManager.printReport(jasperPrint, true);
  
              //Exporting it to an PDF
              JasperExportManager.exportReportToPdfFile(jasperPrint, destinationFile);
  
          } catch (Exception e) {
              System.out.println(e);
          }
      }
  
      private static Document convertStringToDocument(String xmlStr) {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          DocumentBuilder builder;
          try {
              builder = factory.newDocumentBuilder();
              Document doc = builder.parse(new InputSource(new StringReader(xmlStr)));
              return doc;
          } catch (Exception e) {
              e.printStackTrace();
          }
          return null;
      }
  }
  </code></pre>
  
  <p>Source String:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;DATA&gt;
    &lt;ROW&gt;
      &lt;ID&gt;1&lt;/ID&gt;
      &lt;firstName&gt;Testname&lt;/firstName&gt;
      &lt;lastName&gt;Testlast&lt;/lastName&gt;
      &lt;code&gt;12345&lt;/code&gt;
   &lt;/ROW&gt;
   &lt;ROW&gt;
      &lt;ID&gt;2&lt;/ID&gt;
      &lt;firstName&gt;John&lt;/firstName&gt;
      &lt;lastName&gt;Doe&lt;/lastName&gt;
      &lt;code&gt;54321&lt;/code&gt;
   &lt;/ROW&gt;
   &lt;ROW&gt;
      &lt;ID&gt;3&lt;/ID&gt;
      &lt;firstName&gt;Jane&lt;/firstName&gt;
      &lt;lastName&gt;Doe&lt;/lastName&gt;
      &lt;code&gt;22222&lt;/code&gt;
  &lt;/ROW&gt;
  &lt;ROW&gt;
      &lt;ID&gt;4&lt;/ID&gt;
      &lt;firstName&gt;George&lt;/firstName&gt;
      &lt;lastName&gt;Washington&lt;/lastName&gt;
      &lt;code&gt;33333&lt;/code&gt;
  &lt;/ROW&gt;
  &lt;ROW&gt;
      &lt;ID&gt;5&lt;/ID&gt;
      &lt;firstName&gt;John&lt;/firstName&gt;
      &lt;lastName&gt;Adams&lt;/lastName&gt;
      &lt;code&gt;44444&lt;/code&gt;
  &lt;/ROW&gt;
  &lt;ROW&gt;
      &lt;ID&gt;6&lt;/ID&gt;
      &lt;firstName&gt;Thomas &lt;/firstName&gt;
      &lt;lastName&gt;Jefferson&lt;/lastName&gt;
      &lt;code&gt;55555&lt;/code&gt;
  &lt;/ROW&gt;
  &lt;ROW&gt;
      &lt;ID&gt;7&lt;/ID&gt;
      &lt;firstName&gt;James&lt;/firstName&gt;
      &lt;lastName&gt;Madison&lt;/lastName&gt;
      &lt;code&gt;66666&lt;/code&gt;
  &lt;/ROW&gt;
  &lt;ROW&gt;
      &lt;ID&gt;8&lt;/ID&gt;
      &lt;firstName&gt;James&lt;/firstName&gt;
      &lt;lastName&gt;Monroe&lt;/lastName&gt;
      &lt;code&gt;77777&lt;/code&gt;
  &lt;/ROW&gt;
  &lt;ROW&gt;
      &lt;ID&gt;9&lt;/ID&gt;
      &lt;firstName&gt;John Quency&lt;/firstName&gt;
      &lt;lastName&gt;Adams&lt;/lastName&gt;
      &lt;code&gt;88888&lt;/code&gt;
   &lt;/ROW&gt;
   &lt;ROW&gt;
      &lt;ID&gt;10&lt;/ID&gt;
      &lt;firstName&gt;Andrew&lt;/firstName&gt;
      &lt;lastName&gt;Jackson&lt;/lastName&gt;
      &lt;code&gt;99999&lt;/code&gt;
   &lt;/ROW&gt;
   &lt;ROW&gt;
      &lt;ID&gt;11&lt;/ID&gt;
      &lt;firstName&gt;Martin Van&lt;/firstName&gt;
      &lt;lastName&gt;Burren&lt;/lastName&gt;
      &lt;code&gt;0&lt;/code&gt;
   &lt;/ROW&gt;
    &lt;/DATA&gt;
  </code></pre>
  
  <p>Jasper XML---report2.jrxml: </p>
  
  <pre><code>     &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5263a626-fdd2-43a7-b67e-ced19b4c240b"&gt;
          &lt;property name="ireport.zoom" value="1.0"/&gt;
          &lt;property name="ireport.x" value="0"/&gt;
          &lt;property name="ireport.y" value="0"/&gt;
          &lt;field name="firstName" class="java.lang.String"&gt;
              &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
          &lt;/field&gt;
          &lt;field name="lastName" class="java.lang.String"&gt;
                &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
          &lt;/field&gt;
          &lt;field name="code" class="java.lang.Integer"&gt;
               &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
          &lt;/field&gt;
          &lt;variable name="testout" class="java.lang.Integer"&gt;
                &lt;variableExpression&gt;&lt;![CDATA[$V{testout}.valueOf($V{testout}.intValue() + 1 )]]&gt;&lt;/variableExpression&gt;
                &lt;initialValueExpression&gt;&lt;![CDATA[$V{testout}.intValue(0)]]&gt;&lt;/initialValueExpression&gt;
          &lt;/variable&gt;
          &lt;variable name="variable1" class="java.lang.String"/&gt;
          &lt;background&gt;
              &lt;band splitType="Stretch"/&gt;
          &lt;/background&gt;
          &lt;title&gt;
            &lt;band height="71" splitType="Stretch"&gt;
             &lt;staticText&gt;
               &lt;reportElement mode="Opaque" x="0" y="2" width="555" height="55" forecolor="#000000" backcolor="#6699FF" uuid="d2f1857a-a53f-4b65-8960-ff56856000c4"/&gt;
                 &lt;textElement textAlignment="Center"&gt;
                     &lt;font fontName="SansSerif" size="40"/&gt;
                 &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[People Test]]&gt;&lt;/text&gt;
               &lt;/staticText&gt;
            &lt;/band&gt;
        &lt;/title&gt;
      &lt;pageHeader&gt;
          &lt;band height="16" splitType="Stretch"/&gt;
      &lt;/pageHeader&gt;
      &lt;columnHeader&gt;
          &lt;band height="33" splitType="Stretch"&gt;
              &lt;elementGroup&gt;
                  &lt;staticText&gt;
                      &lt;reportElement mode="Opaque" x="360" y="0" width="195" height="20" backcolor="#999999" uuid="2311af72-d724-4003-b5e4-151bc23e41a8"/&gt;
                      &lt;textElement textAlignment="Center"&gt;
                          &lt;font size="14" isBold="true"/&gt;
                      &lt;/textElement&gt;
                      &lt;text&gt;&lt;![CDATA[Code]]&gt;&lt;/text&gt;
                   &lt;/staticText&gt;
                   &lt;staticText&gt;
                      &lt;reportElement mode="Opaque" x="168" y="0" width="192" height="20" backcolor="#999999" uuid="0fc99eec-a7c3-468f-ba64-30f3140131b2"/&gt;
                      &lt;textElement textAlignment="Center"&gt;
                          &lt;font size="14" isBold="true"/&gt;
                      &lt;/textElement&gt;
                      &lt;text&gt;&lt;![CDATA[Last]]&gt;&lt;/text&gt;
                  &lt;/staticText&gt;
                  &lt;staticText&gt;
                      &lt;reportElement mode="Opaque" x="0" y="0" width="168" height="20" backcolor="#999999" uuid="b0a4ccab-fff0-4a77-ad52-1e4132a627e2"/&gt;
                      &lt;textElement textAlignment="Center"&gt;
                          &lt;font size="14" isBold="true"/&gt;
                      &lt;/textElement&gt;
                      &lt;text&gt;&lt;![CDATA[First ]]&gt;&lt;/text&gt;
                  &lt;/staticText&gt;
              &lt;/elementGroup&gt;
           &lt;/band&gt;
       &lt;/columnHeader&gt;
       &lt;detail&gt;
           &lt;band height="36" splitType="Stretch"&gt;
              &lt;textField&gt;
                  &lt;reportElement x="0" y="0" width="168" height="20" uuid="ca9be109-f4d6-48d6-988f-a5d78352e578"/&gt;
                  &lt;textElement textAlignment="Center"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{firstName}]]&gt;&lt;/textFieldExpression&gt;
               &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement x="168" y="0" width="192" height="20" uuid="1255a5e6-59b1-4d49-92e0-c6b64a0cbf93"/&gt;
                  &lt;textElement textAlignment="Center"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{lastName}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement x="360" y="0" width="195" height="20" uuid="1099096e-17b7-480c-8e9c-ffb50669326a"/&gt;
                  &lt;textElement textAlignment="Center"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{code}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
           &lt;/band&gt;
       &lt;/detail&gt;
       &lt;columnFooter&gt;
          &lt;band height="28" splitType="Stretch"/&gt;
       &lt;/columnFooter&gt;
       &lt;pageFooter&gt;
           &lt;band height="214" splitType="Stretch"&gt;
              &lt;image&gt;
                  &lt;reportElement mode="Opaque" x="194" y="0" width="166" height="178" backcolor="#000000" uuid="4299a501-2792-4c76-bc6d-506a480fa1a6"/&gt;
                  &lt;imageExpression&gt;&lt;![CDATA["C:\\workspace\\testProject\\testing\\sources\\Turkish_Van_Cat.jpg"]]&gt;&lt;/imageExpression&gt;
              &lt;/image&gt;
               &lt;textField&gt;
                  &lt;reportElement x="197" y="198" width="163" height="16" uuid="801deb03-5452-4bc6-935e-2c15a8977721"/&gt;
                  &lt;textElement textAlignment="Center"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$V{PAGE_NUMBER}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
       &lt;/pageFooter&gt;
       &lt;summary&gt;
          &lt;band height="104" splitType="Stretch"/&gt;
      &lt;/summary&gt;
   &lt;/jasperReport&gt;
  </code></pre>