diff --git a/main/src/com/google/refine/importers/tree/TreeImportingParserBase.java b/main/src/com/google/refine/importers/tree/TreeImportingParserBase.java index 58468b336..1ce6b5195 100644 --- a/main/src/com/google/refine/importers/tree/TreeImportingParserBase.java +++ b/main/src/com/google/refine/importers/tree/TreeImportingParserBase.java @@ -189,7 +189,17 @@ abstract public class TreeImportingParserBase implements ImportingParser { List exceptions ) { String[] recordPath = JSONUtilities.getStringArray(options, "recordPath"); - - XmlImportUtilities.importTreeData(treeParser, project, recordPath, rootColumnGroup, limit); + int limit2 = JSONUtilities.getInt(options, "limit", -1); + if (limit > 0) { + if (limit2 > 0) { + limit2 = Math.min(limit, limit2); + } else { + limit2 = limit; + } + } + if (limit2 == 0) { // shouldn't really happen, but be sure since 0 is stop signal + limit2 = -1; + } + XmlImportUtilities.importTreeData(treeParser, project, recordPath, rootColumnGroup, limit2); } } diff --git a/main/src/com/google/refine/importers/tree/XmlImportUtilities.java b/main/src/com/google/refine/importers/tree/XmlImportUtilities.java index 0d048fcb7..ca2b99221 100644 --- a/main/src/com/google/refine/importers/tree/XmlImportUtilities.java +++ b/main/src/com/google/refine/importers/tree/XmlImportUtilities.java @@ -246,14 +246,14 @@ public class XmlImportUtilities extends TreeImportUtilities { ) { logger.trace("importTreeData(TreeReader, Project, String[], ImportColumnGroup)"); try { - while (parser.hasNext() && (limit <= 0 || project.rows.size() < limit)) { + while (parser.hasNext()) { Token eventType = parser.next(); if (eventType == Token.StartEntity) { - findRecord(project, parser, recordPath, 0, rootColumnGroup, limit); - logger.info("Project rows after findRecord = "+project.rows.size()); + findRecord(project, parser, recordPath, 0, rootColumnGroup, limit--); } } } catch (TreeReaderException e) { + // TODO: This error needs to be reported to the browser/user logger.error("Exception from XML parse",e); } } @@ -290,11 +290,10 @@ public class XmlImportUtilities extends TreeImportUtilities { String fullName = composeName(parser.getPrefix(), localName); if (recordPathSegment.equals(localName) || recordPathSegment.equals(fullName)) { if (pathIndex < recordPath.length - 1) { - while (parser.hasNext() && (limit <= 0 || project.rows.size() < limit)) { + while (parser.hasNext() && limit != 0) { Token eventType = parser.next(); if (eventType == Token.StartEntity) { - // TODO: find instead of process?? - findRecord(project, parser, recordPath, pathIndex + 1, rootColumnGroup, limit); + findRecord(project, parser, recordPath, pathIndex + 1, rootColumnGroup, limit--); } else if (eventType == Token.EndEntity) { break; } else if (eventType == Token.Value) {