Skip to content

Commit

Permalink
0002314: dbimport of xml (XmlDataReader) does not handle xsi:nil corr…
Browse files Browse the repository at this point in the history
…ectly
  • Loading branch information
chenson42 committed Jun 13, 2015
1 parent 8898ddc commit cdc50d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Expand Up @@ -77,7 +77,6 @@ public void open(DataContext context) {

protected Object readNext() {
try {
boolean nullValue = false;
Map<String, String> rowData = new LinkedHashMap<String, String>();
String columnName = null;
Table lastTable = this.table;
Expand All @@ -86,12 +85,7 @@ protected Object readNext() {
switch (eventType) {
case XmlPullParser.TEXT:
if (columnName != null) {
if (!nullValue) {
rowData.put(columnName, parser.getText());
} else {
rowData.put(columnName, null);
}
nullValue = false;
rowData.put(columnName, parser.getText());
columnName = null;
}
break;
Expand Down Expand Up @@ -130,6 +124,7 @@ protected Object readNext() {
}
}
} else if ("data".equalsIgnoreCase(name)) {
boolean nullValue = false;
for (int i = 0; i < parser.getAttributeCount(); i++) {
String attributeName = parser.getAttributeName(i);
String attributeValue = parser.getAttributeValue(i);
Expand All @@ -139,6 +134,11 @@ protected Object readNext() {
nullValue = true;
}
}

if (nullValue) {
rowData.put(columnName, null);
columnName = null;
}
} else if ("batch".equalsIgnoreCase(name)) {
batch = new Batch();
for (int i = 0; i < parser.getAttributeCount(); i++) {
Expand All @@ -165,14 +165,14 @@ protected Object readNext() {
String[] columnValues = rowData.values().toArray(
new String[rowData.values().size()]);
data.putParsedData(CsvData.ROW_DATA, columnValues);
rowData = new LinkedHashMap<String, String>();
if (lastTable == null || !lastTable.equals(table)) {
return table;
} else {
return data;
}
} else if ("data".equalsIgnoreCase(name)) {
columnName = null;
nullValue = false;
}

break;
Expand Down
Expand Up @@ -178,7 +178,7 @@ protected void readNext() {
next.add(table);
}
next.add(data);
rowData = new HashMap<String, String>();
rowData = new LinkedHashMap<String, String>();
} else if ("table_data".equalsIgnoreCase(name)) {
if (batch != null) {
batch.setComplete(true);
Expand Down

0 comments on commit cdc50d8

Please sign in to comment.