@@ -215,12 +215,16 @@ fn main() -> std::io::Result<()> {
215
215
}
216
216
else if path. len ( ) > table. path . len ( ) {
217
217
for i in 0 ..table. columns . len ( ) {
218
- if path == table. columns [ i] . path {
218
+ if path == table. columns [ i] . path { // This start tag matches one of the defined columns
219
+
220
+ // Handle 'subtable' case (the 'cols' entry has 'cols' of its own)
219
221
if table. columns [ i] . subtable . is_some ( ) {
220
222
tables. push ( table) ;
221
223
table = & table. columns [ i] . subtable . as_ref ( ) . unwrap ( ) ;
222
224
break ;
223
225
}
226
+
227
+ // Handle the 'attr' case where the content is read from an attribute of this tag
224
228
if let Some ( request) = table. columns [ i] . attr {
225
229
for res in e. attributes ( ) {
226
230
if let Ok ( attr) = res {
@@ -241,6 +245,8 @@ fn main() -> std::io::Result<()> {
241
245
eprintln ! ( "Column {} requested attribute {} not found" , table. columns[ i] . name, request) ;
242
246
}
243
247
}
248
+
249
+ // Set the appropriate convert flag for the following data in case the 'conv' option is present
244
250
match table. columns [ i] . convert {
245
251
None => ( ) ,
246
252
Some ( "xml-to-text" ) => xmltotext = true ,
@@ -291,11 +297,16 @@ fn main() -> std::io::Result<()> {
291
297
} ,
292
298
Ok ( Event :: End ( _) ) => {
293
299
if path == table. path {
300
+
301
+ // End tag of a subtable; write the first column value of the parent table as the first column of the subtable
294
302
if !tables. is_empty ( ) {
295
303
table. write ( & tables. last ( ) . unwrap ( ) . columns [ 0 ] . value . borrow ( ) ) ;
296
304
table. write ( "\t " ) ;
297
305
}
306
+
307
+ // Now write out the other column values
298
308
for i in 0 ..table. columns . len ( ) {
309
+ if table. columns [ i] . subtable . is_some ( ) { continue ; }
299
310
if i > 0 { table. write ( "\t " ) ; }
300
311
if table. columns [ i] . value . borrow ( ) . is_empty ( ) { table. write ( "\\ N" ) ; }
301
312
else {
0 commit comments