We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Linq how display list of string

I’m using linq reporting engine through a DataSet.
In my model i have an attribute which is a List of String: private List targheAuto;

How can i write out all the strings contained in the list ? I tryed to use <> statement , but it doesn’t work with such a list of string…

Thanks

Hi Simone,

Thanks for your inquiry. Please use the following code example to achieve your requirements. We suggest you please read following articles. Hope this helps you.

Outputting Sequential Data
Working with Common Data Bands

DocumentBuilder builder = new DocumentBuilder();
builder.write("The items are: <><>, <>and others.");
Document doc = builder.getDocument();

ArrayList arrList = new ArrayList();
arrList.add("Item1");
arrList.add("Item2");
arrList.add("Item3");

ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, arrList, "items");

doc.save(MyDir + "out.docx");

Hi, thanks for the feedback, but i’m using a dataSet populated from XML:

DataSet dataSet = new DataSet();
dataSet.readXml(new ByteArrayInputStream(dati.getBytes(StandardCharsets.UTF_8)));

ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
engine.getKnownTypes().add(Util.class);
engine.getKnownTypes().add(Date.class);
engine.buildReport(doc, dataSet);


where dati is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>


xxx
dj333gz
du23232jj
dd2322d
sfdsfsdf




In my template i try to use:

<><><>

But is doesnt work

That's the error:
javax.xml.ws.soap.SOAPFaultException: Errore generico PDF. An error has been encountered at the end of expression 'targa in targheAuto]>'. Can not iterate over an instance of type 'class java.lang.String'.


Hi Simone,

Thanks for your inquiry. Please check the following highlighted code snippet and template syntax. Hope this helps you.

<><><>

Document doc = new Document(MyDir + "in.docx");
DataSet dataSet =
new DataSet();
dataSet.readXml(
MyDir + "in.xml");

ReportingEngine engine =
new ReportingEngine();
engine.setOptions(ReportBuildOptions.
ALLOW_MISSING_MEMBERS);
engine.buildReport(doc, dataSet.getTables().get(0), "richiedente");
doc.save(
MyDir + "17.6.docx");

Hi Tahir, i’m sorry but it doesn’t work either.

targheAuto is a list of values:
dj333gz
du23232jj

and it should display 2 values and not only one.

Simone




Hi Simone,

Thanks for your inquiry. The DataTable cannot have two columns with same name. Please check the following correct XML.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
xxx
dj333gz
dd2322d
xxx
du23232jj
sfdsfsdf

It’s the way you get the lists in XML: two or more columns with same name !
The xml you attached is wrong: there are two instances of richiedente and that’s not what we have: we have an instance of richiedente containing two instances of targheAuto…
Hope you’ll correct this issue.

thanks

Simone

Hi Simone,

Thanks for your inquiry. Please note that com.aspose.words.net.System.Data.DataSet.readXml method mimics the .NET DataSet.ReadXml method. This method reads the XML and convert it into DataSet that contain DataTables.

In your case, you need to read the XML using Java code and create an ArrayList and pass it to ReportingEngine.buildReport method. The LINQ Reporting syntax will be
<<foreach [t in richiedente]>><<[t]>><</foreach>>.

Document doc = new Document(MyDir + "in.docx");
ArrayList arrList = new ArrayList();

//Your code...
arrList.add(...);
arrList.add(...);

ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
engine.buildReport(doc, arrList, "richiedente");
doc.save(MyDir + "17.6.docx");

I’m not happy about it.

Hi Simone,

The Java API does not have DataSet.ReadXml method to read XML. So, we introduced com.aspose.words.net.System.Data.DataSet to read XML and use the DataSet, DataTable, and DataRow as data source in mail merge and LINQ Reporting engine.

Please note that you can import proper XML into com.aspose.words.net.System.Data.DataSet using Aspose.Words. You can get the tables from DataSet and rows/cells from DataTable. In DataTable, duplicate column names are not allowed. Please check the following link.
Duplicate DataTable column names
simone.padovan:
targheAuto is a list of values:
dj333gz
du23232jj
Your query is related to read this XML. In this case, we suggest you please read the XML as shown below. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
ArrayList arrList = new ArrayList();

File fXmlFile = new File(MyDir + "input.xml");
javax.xml.parsers.DocumentBuilderFactory dbFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
javax.xml.parsers.DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
org.w3c.dom.Document docXML = dBuilder.parse(fXmlFile);
docXML.getDocumentElement().normalize();

org.w3c.dom.NodeList nList = docXML.getElementsByTagName("richiedente");
for (int temp = 0; temp < nList.getLength(); temp++) {

org.w3c.dom.Node nNode = nList.item(temp);

if (nNode.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {

org.w3c.dom.Element eElement = (org.w3c.dom.Element) nNode;
for(int i = 0; i< eElement.getElementsByTagName("targheAuto").getLength(); i ++)
{
arrList.add(eElement.getElementsByTagName("targheAuto").item(i).getTextContent());
}

}
}

ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
engine.buildReport(doc, arrList, "richiedente");
doc.save(MyDir + "17.6.docx");