net.sf.jmatchparser.util.csv
Class XMLCSVReader

java.lang.Object
  extended by net.sf.jmatchparser.util.csv.AbstractCSVReader
      extended by net.sf.jmatchparser.util.csv.XMLCSVReader

public class XMLCSVReader
extends AbstractCSVReader

Class to read data from an XML file as if it was a CSV (Comma Separated Value) file.


Constructor Summary
XMLCSVReader(Document doc)
          Create a new XMLCSVReader that reads from the given DOM document.
XMLCSVReader(Document doc, String rowTag, String... cellTags)
          Create a new XMLCSVReader that reads from the given DOM document.
 
Method Summary
 void close()
          Close this reader.
 String[] read()
          Read a row from this XML file.
 String[] read(int[] fileIndex)
          Read a row from this XML file.
 
Methods inherited from class net.sf.jmatchparser.util.csv.AbstractCSVReader
read, read, writeTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLCSVReader

public XMLCSVReader(Document doc)
Create a new XMLCSVReader that reads from the given DOM document. All child elements of the document element are considered rows, and all their child elements are considered cells.

Parameters:
doc - the Document

XMLCSVReader

public XMLCSVReader(Document doc,
                    String rowTag,
                    String... cellTags)
Create a new XMLCSVReader that reads from the given DOM document. All child elements of the document element that have the row tag as name (or all of them if the row tag is *) are considered rows, and all their child elements that have one of the cell tags as name are considered cells. In case there is more than one cell tag, the cell tag in the list of cell tags is used to determine the position in the result row. If a cell tag matches more than once in a row, all the fields before the cell tag are added to the result row, and a complete set of empty fields is used to parse the rest of the row. Cell tags that are not matched result in empty strings, unless they would be at the end of the row in the last run.

Parameters:
doc - the Document
rowTag - the name of row elements
cellTags - the names of cell elements
Method Detail

close

public void close()
           throws IOException
Close this reader. This is a no-op.

Specified by:
close in class AbstractCSVReader
Throws:
IOException

read

public String[] read()
              throws IOException
Read a row from this XML file.

Specified by:
read in class AbstractCSVReader
Throws:
IOException

read

public String[] read(int[] fileIndex)
Read a row from this XML file. If the row has a @file attribute and the fileIndex argument is non-null, the value of that file attribute is stored into the first element of that array.

Parameters:
fileIndex - Array to store the file index to, if needed


Copyright © 2011. All Rights Reserved.