forked from jaerith/ONIX-Data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnixLegacyParser.cs
683 lines (549 loc) · 26.2 KB
/
OnixLegacyParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.Xml.Schema;
using OnixData.Extensions;
using OnixData.Legacy;
namespace OnixData
{
/// <summary>
///
/// This class serves as a way to parse files of the ONIX 2.1 standard (and earlier).
/// You can use this class to either:
///
/// a.) Deserialize and load the entire file into memory
/// b.) Enumerate through the file record by record, loading each into memory one at a time
///
/// </summary>
public class OnixLegacyParser : IDisposable, IEnumerable
{
#region CONSTANTS
private const int CONST_MSG_REFERENCE_LENGTH = 500;
private const int CONST_BLOCK_COUNT_SIZE = 50000000;
private const string CONST_ONIX_MESSAGE_REFERENCE_TAG = "ONIXMessage";
private const string CONST_ONIX_MESSAGE_SHORT_TAG = "ONIXmessage";
private const string CONST_ONIX_HEADER_REFERENCE_TAG = "Header";
private const string CONST_ONIX_HEADER_SHORT_TAG = "header";
#endregion
private bool DebugFlag = true;
private bool ParserRefVerFlag = false;
private bool ParserRVWFlag = false;
private bool PerformValidFlag = false;
private StringBuilder ParserFileContent = null;
private FileInfo ParserFileInfo = null;
// private XmlReader LegacyOnixReader = null;
private XmlTextReader LegacyOnixReader = null;
private OnixLegacyMessage LegacyOnixMessage = null;
public bool PerformValidation
{
get { return this.PerformValidFlag; }
}
public bool ReferenceVersion
{
get { return this.ParserRefVerFlag; }
}
public bool ShouldApplyDefaults { get; set; }
public bool AlwaysReturnInputXml { get; set; }
public OnixLegacyParser(FileInfo LegacyOnixFilepath,
bool ExecuteValidation,
bool PreprocessOnixFile = true,
bool LoadEntireFileIntoMemory = false)
{
if (!File.Exists(LegacyOnixFilepath.FullName))
throw new Exception("ERROR! File(" + LegacyOnixFilepath + ") does not exist.");
AlwaysReturnInputXml = false;
this.ParserFileInfo = LegacyOnixFilepath;
this.ParserRVWFlag = true;
this.ShouldApplyDefaults = true;
this.PerformValidFlag = ExecuteValidation;
if (PreprocessOnixFile)
LegacyOnixFilepath.ReplaceIsoLatinEncodings(true);
// this.LegacyOnixReader = CreateXmlReader(this.ParserFileInfo, this.ParserRVWFlag, this.PerformValidFlag);
this.LegacyOnixReader = CreateXmlTextReader(this.ParserFileInfo);
bool ReferenceVersion = DetectVersionReference(LegacyOnixFilepath);
string sOnixMsgTag = ReferenceVersion ? CONST_ONIX_MESSAGE_REFERENCE_TAG : CONST_ONIX_MESSAGE_SHORT_TAG;
this.ParserRefVerFlag = ReferenceVersion;
if (LoadEntireFileIntoMemory)
{
this.LegacyOnixMessage =
CreateOnixXmlMsgSerializer(sOnixMsgTag).Deserialize(this.LegacyOnixReader) as OnixLegacyMessage;
}
else
this.LegacyOnixMessage = null;
}
public OnixLegacyParser(bool ExecuteValidation,
FileInfo LegacyOnixFilepath,
bool ReferenceVersion,
bool PreprocessOnixFile = true,
bool LoadEntireFileIntoMemory = false)
{
string sOnixMsgTag = ReferenceVersion ? CONST_ONIX_MESSAGE_REFERENCE_TAG : CONST_ONIX_MESSAGE_SHORT_TAG;
AlwaysReturnInputXml = false;
if (!File.Exists(LegacyOnixFilepath.FullName))
throw new Exception("ERROR! File(" + LegacyOnixFilepath + ") does not exist.");
this.ParserRefVerFlag = ReferenceVersion;
this.ParserFileInfo = LegacyOnixFilepath;
this.ParserRVWFlag = true;
this.ShouldApplyDefaults = true;
this.PerformValidFlag = ExecuteValidation;
if (PreprocessOnixFile)
LegacyOnixFilepath.ReplaceIsoLatinEncodings(true);
// this.LegacyOnixReader = CreateXmlReader(this.ParserFileInfo, this.ParserRVWFlag, this.PerformValidFlag);
this.LegacyOnixReader = CreateXmlTextReader(this.ParserFileInfo);
if (LoadEntireFileIntoMemory)
{
this.LegacyOnixMessage =
CreateOnixXmlMsgSerializer(sOnixMsgTag).Deserialize(this.LegacyOnixReader) as OnixLegacyMessage;
}
else
this.LegacyOnixMessage = null;
}
public OnixLegacyParser(string LegacyOnixContent,
bool ExecuteValidation,
bool PreprocessOnixFile = true,
bool LoadEntireFileIntoMemory = false)
{
if (String.IsNullOrEmpty(LegacyOnixContent))
throw new Exception("ERROR! ONIX content provided is empty.");
AlwaysReturnInputXml = false;
this.ParserFileContent = new StringBuilder(LegacyOnixContent);
this.ParserRVWFlag = true;
this.ShouldApplyDefaults = true;
this.PerformValidFlag = ExecuteValidation;
if (PreprocessOnixFile)
{
ParserFileContent.ReplaceIsoLatinEncodings();
ParserFileContent.FilterIncompleteEncodings();
}
// this.LegacyOnixReader = CreateXmlReader(this.ParserFileContent, this.ParserRVWFlag, this.PerformValidFlag);
this.LegacyOnixReader = CreateXmlTextReader(this.ParserFileContent);
bool ReferenceVersion = DetectVersionReference(ParserFileContent);
string sOnixMsgTag = ReferenceVersion ? CONST_ONIX_MESSAGE_REFERENCE_TAG : CONST_ONIX_MESSAGE_SHORT_TAG;
this.ParserRefVerFlag = ReferenceVersion;
if (LoadEntireFileIntoMemory)
{
this.LegacyOnixMessage =
CreateOnixXmlMsgSerializer(sOnixMsgTag).Deserialize(this.LegacyOnixReader) as OnixLegacyMessage;
}
else
this.LegacyOnixMessage = null;
}
public OnixLegacyParser(bool ExecuteValidation,
string LegacyOnixContent,
bool ReferenceVersion,
bool PreprocessOnixFile = true,
bool LoadEntireFileIntoMemory = false)
{
string sOnixMsgTag = ReferenceVersion ? CONST_ONIX_MESSAGE_REFERENCE_TAG : CONST_ONIX_MESSAGE_SHORT_TAG;
AlwaysReturnInputXml = false;
if (String.IsNullOrEmpty(LegacyOnixContent))
throw new Exception("ERROR! ONIX content provided is empty.");
this.ParserRefVerFlag = ReferenceVersion;
this.ParserFileContent = new StringBuilder(LegacyOnixContent);
this.ParserRVWFlag = true;
this.ShouldApplyDefaults = true;
this.PerformValidFlag = ExecuteValidation;
if (PreprocessOnixFile)
{
ParserFileContent.ReplaceIsoLatinEncodings();
ParserFileContent.FilterIncompleteEncodings();
}
// this.LegacyOnixReader = CreateXmlReader(this.ParserFileContent, this.ParserRVWFlag, this.PerformValidFlag);
this.LegacyOnixReader = CreateXmlTextReader(this.ParserFileContent);
if (LoadEntireFileIntoMemory)
{
this.LegacyOnixMessage =
CreateOnixXmlMsgSerializer(sOnixMsgTag).Deserialize(this.LegacyOnixReader) as OnixLegacyMessage;
}
else
this.LegacyOnixMessage = null;
}
public XmlReader CreateXmlReader()
{
XmlReader OnixReader =
(this.ParserFileInfo != null) ?
CreateXmlReader(this.ParserFileInfo, this.ParserRVWFlag, false) : CreateXmlReader(this.ParserFileContent, this.ParserRVWFlag, false);
return OnixReader;
}
/// <summary>
///
/// This method will prepare the XmlReader that we will use to read the ONIX XML file.
///
/// <param name="CurrOnixFilepath">The path to the ONIX file</param>
/// <param name="ReportValidationWarnings">The indicator for whether we should report validation warnings to the caller</param>
/// <param name="ExecutionValidation">The indicator for whether or not the ONIX file should be validated</param>
/// <returns>The XmlReader that will be used to read the ONIX file</returns>
/// </summary>
static public XmlReader CreateXmlReader(FileInfo LegacyOnixFilepath, bool ReportValidationWarnings, bool ExecutionValidation)
{
bool bUseXSD = true;
bool bUseDTD = false;
StringBuilder InvalidErrMsg = new StringBuilder();
XmlReader OnixXmlReader = null;
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.None;
settings.DtdProcessing = DtdProcessing.Ignore;
if (ExecutionValidation)
{
settings.ConformanceLevel = ConformanceLevel.Document;
if (bUseXSD)
{
/*
* NOTE: XSD Validation does not appear to be working correctly yet
*
XmlSchemaSet schemas = new XmlSchemaSet();
string XsdFilepath = "";
if (ParserRefVerFlag)
XsdFilepath = @"C:\ONIX_XSD\2.1\ONIX_BookProduct_Release2.1_reference.xsd";
else
XsdFilepath = @"C:\ONIX_XSD\2.1\ONIX_BookProduct_Release2.1_short.xsd";
schemas.Add(null, XmlReader.Create(new StringReader(File.ReadAllText(XsdFilepath))));
settings.Schemas = schemas;
settings.ValidationType = ValidationType.Schema;
if (ReportValidationWarnings)
settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
else
settings.ValidationFlags &= ~(XmlSchemaValidationFlags.ReportValidationWarnings);
// settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
*/
}
/*
* NOTE: DTD Validation does not appear that it will ever work correctly on the .NET platform
*
if (bUseDTD)
{
settings.DtdProcessing = DtdProcessing.Parse;
settings.ValidationType = ValidationType.DTD;
settings.ValidationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
System.Xml.XmlResolver newXmlResolver = new System.Xml.XmlUrlResolver();
newXmlResolver.ResolveUri(new Uri("C:\\ONIX_DTD\\2.1\\short"), "onix-international.dtd");
settings.XmlResolver = newXmlResolver;
settings.ValidationEventHandler += new ValidationEventHandler(delegate(object sender, ValidationEventArgs args)
{
// InvalidErrMsg.AppendLine(args.Message);
throw new Exception(args.Message);
});
}
*/
}
OnixXmlReader = XmlReader.Create(LegacyOnixFilepath.FullName, settings);
return OnixXmlReader;
}
static public XmlReader CreateXmlReader(StringBuilder LegacyOnixContent, bool ReportValidationWarnings, bool ExecutionValidation)
{
bool bUseXSD = true;
StringBuilder InvalidErrMsg = new StringBuilder();
XmlReader OnixXmlReader = null;
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.None;
settings.DtdProcessing = DtdProcessing.Ignore;
if (ExecutionValidation)
{
settings.ConformanceLevel = ConformanceLevel.Document;
if (bUseXSD)
{ /* NOTE: XSD Validation does not appear to be working correctly yet */ }
/* NOTE: DTD Validation does not appear that it will ever work correctly on the .NET platform */
}
OnixXmlReader = XmlReader.Create(new StringReader(LegacyOnixContent.ToString()), settings);
return OnixXmlReader;
}
static public XmlTextReader CreateXmlTextReader(FileInfo LegacyOnixFilepath)
{
XmlTextReader OnixXmlReader = new XmlTextReader(LegacyOnixFilepath.FullName);
OnixXmlReader.XmlResolver = null;
OnixXmlReader.DtdProcessing = DtdProcessing.Ignore;
OnixXmlReader.Namespaces = false;
return OnixXmlReader;
}
static public XmlTextReader CreateXmlTextReader(StringBuilder LegacyOnixContent)
{
XmlTextReader OnixXmlReader = new XmlTextReader(new StringReader(LegacyOnixContent.ToString()));
OnixXmlReader.XmlResolver = null;
OnixXmlReader.DtdProcessing = DtdProcessing.Ignore;
OnixXmlReader.Namespaces = false;
return OnixXmlReader;
}
static public XmlSerializer CreateOnixXmlMsgSerializer(string psOnixMsgTag)
{
var OnixXmlSerializer = new XmlSerializer(typeof(OnixLegacyMessage), new XmlRootAttribute(psOnixMsgTag));
return OnixXmlSerializer;
}
/// <summary>
///
/// This property will return the header of an ONIX file. If the file has already been loaded
/// into memory, it will extract the header from the internal member reader. If not, it will
/// open the file temporarily and extract it from there.
///
/// <returns>The header of the ONIX file</returns>
/// </summary>
public OnixLegacyHeader MessageHeader
{
get
{
string sOnixHdrTag =
this.ParserRefVerFlag ? CONST_ONIX_HEADER_REFERENCE_TAG : CONST_ONIX_HEADER_SHORT_TAG;
OnixLegacyHeader LegacyHeader = new OnixLegacyHeader();
if (this.LegacyOnixMessage != null)
LegacyHeader = this.LegacyOnixMessage.Header;
else
{
using (XmlReader OnixReader = CreateXmlReader())
{
XmlDocument XMLDoc = new XmlDocument();
XMLDoc.Load(OnixReader);
XmlNodeList HeaderList = XMLDoc.GetElementsByTagName(sOnixHdrTag);
if ((HeaderList != null) && (HeaderList.Count > 0))
{
XmlNode HeaderNode = HeaderList.Item(0);
string sHeaderBody = HeaderNode.OuterXml;
LegacyHeader =
new XmlSerializer(typeof(OnixLegacyHeader), new XmlRootAttribute(sOnixHdrTag))
.Deserialize(new StringReader(sHeaderBody)) as OnixLegacyHeader;
}
}
}
return LegacyHeader;
}
}
public OnixLegacyMessage Message
{
get
{
return LegacyOnixMessage;
}
}
public void Dispose()
{
if (this.LegacyOnixReader != null)
{
this.LegacyOnixReader.Close();
this.LegacyOnixReader = null;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return (IEnumerator) GetEnumerator();
}
public OnixLegacyEnumerator GetEnumerator()
{
if (this.ParserFileInfo != null)
return new OnixLegacyEnumerator(this, this.ParserFileInfo);
else if (this.ParserFileContent != null)
return new OnixLegacyEnumerator(this, this.ParserFileContent);
else
return null;
}
/// <summary>
///
/// This method was intended to provide the functionality of validating a legacy ONIX file against its
/// respective DTD/XSD. Unfortunately, though, the .NET platform does not seem to be compatible with
/// parsing and understanding a complex schema as specified in the ONIX standard. So, it seems that this
/// method will never come into fruition.
///
/// <returns>The Boolean that indicates whether or not the ONIX file is valid</returns>
/// </summary>
public bool ValidateFile()
{
bool ValidOnixFile = true;
/*
* NOTE: XSD Validation is proving to be consistently problematic
*
try
{
XmlReaderSettings TempReaderSettings = new XmlReaderSettings() { DtdProcessing = DtdProcessing.Ignore };
using (XmlReader TempXmlReader = XmlReader.Create(ParserFileInfo.FullName, TempReaderSettings))
{
XDocument OnixDoc = XDocument.Load(TempXmlReader);
XmlSchemaSet schemas = new XmlSchemaSet();
string XsdFilepath = "";
if (ParserRefVerFlag)
XsdFilepath = @"C:\ONIX_XSD\2.1\ONIX_BookProduct_Release2.1_reference.xsd";
else
XsdFilepath = @"C:\ONIX_XSD\2.1\ONIX_BookProduct_Release2.1_short.xsd";
schemas.Add(null, XmlReader.Create(new StringReader(File.ReadAllText(XsdFilepath))));
schemas.Compile();
OnixDoc.Validate(schemas, (o, e) =>
{
Console.WriteLine("{0}", e.Message);
ValidOnixFile = false;
});
}
}
catch (Exception ex)
{
ValidOnixFile = false;
}
*/
return ValidOnixFile;
}
#region Support Methods
/// <summary>
///
/// This method will help determine whether the XML structure of an ONIX file belongs to the 'Reference' type
/// of ONIX (i.e., verbose tags) or the 'Short' type of ONIX (i.e., alphanumeric tags).
///
/// <param name="LegacyOnixFilepath">The path to the ONIX file</param>
/// <returns>The Boolean that indicates whether or not the ONIX file belongs to the 'Reference' type</returns>
/// </summary>
public bool DetectVersionReference(FileInfo LegacyOnixFileInfo)
{
bool bReferenceVersion = true;
if (LegacyOnixFileInfo.Length < CONST_MSG_REFERENCE_LENGTH)
throw new Exception("ERROR! ONIX File is smaller than expected!");
byte[] buffer = new byte[CONST_MSG_REFERENCE_LENGTH];
using (FileStream fs = new FileStream(LegacyOnixFileInfo.FullName, FileMode.Open, FileAccess.Read))
{
fs.Read(buffer, 0, buffer.Length);
fs.Close();
}
string sRefMsgTag = "<" + CONST_ONIX_MESSAGE_REFERENCE_TAG;
string sFileHead = Encoding.Default.GetString(buffer);
if (sFileHead.Contains(sRefMsgTag))
bReferenceVersion = true;
else
bReferenceVersion = false;
return bReferenceVersion;
}
public bool DetectVersionReference(StringBuilder LegacyOnixContent)
{
bool bReferenceVersion = true;
if (LegacyOnixContent.Length < CONST_MSG_REFERENCE_LENGTH)
throw new Exception("ERROR! ONIX File is smaller than expected!");
string sRefMsgTag = "<" + CONST_ONIX_MESSAGE_REFERENCE_TAG;
string sFileHead = LegacyOnixContent.ToString().Substring(0, CONST_MSG_REFERENCE_LENGTH);
if (sFileHead.Contains(sRefMsgTag))
bReferenceVersion = true;
else
bReferenceVersion = false;
return bReferenceVersion;
}
#endregion
}
/// <summary>
///
/// This class can be useful in the case that one wants to iterate through an ONIX file, even if it has a bad record due to:
///
/// a.) incorrect XML syntax
/// b.) invalid text within a XML document (like certain hexadecimal Unicode)
/// d.) improper tag placement
/// d.) invalid data types
///
/// In that way, the user of the class can investigate each record on a case-by-case basis, and the file can be processed
/// without a sole record preventing the rest of the file from being handled.
///
/// NOTE: It is still recommended that the files be validated through an alternate process before using this class.
///
/// </summary>
public class OnixLegacyEnumerator : IDisposable, IEnumerator
{
private OnixLegacyParser OnixParser = null;
private XmlTextReader OnixReader = null;
private int CurrentIndex = -1;
private string ProductXmlTag = null;
private List<string> OtherTextList = new List<string>();
private XmlDocument OnixDoc = null;
private XmlNodeList ProductList = null;
private OnixLegacyHeader OnixHeader = null;
private OnixLegacyProduct CurrentRecord = null;
private XmlSerializer ProductSerializer = null;
public OnixLegacyEnumerator(OnixLegacyParser ProvidedParser, FileInfo LegacyOnixFilepath)
{
this.ProductXmlTag = ProvidedParser.ReferenceVersion ? "Product" : "product";
this.OnixParser = ProvidedParser;
// this.OnixReader = OnixLegacyParser.CreateXmlReader(LegacyOnixFilepath, false, ProvidedParser.PerformValidation);
this.OnixReader = OnixLegacyParser.CreateXmlTextReader(LegacyOnixFilepath);
ProductSerializer = new XmlSerializer(typeof(OnixLegacyProduct), new XmlRootAttribute(this.ProductXmlTag));
ProductSerializer.UnknownElement += (s, e) =>
{
if (((e.Element.LocalName == "Text") || (e.Element.LocalName == "d104")) &&
e.ObjectBeingDeserialized is OnixLegacyOtherText)
{
OtherTextList.Add(e.Element.InnerText);
}
};
}
public OnixLegacyEnumerator(OnixLegacyParser ProvidedParser, StringBuilder LegacyOnixContent)
{
this.ProductXmlTag = ProvidedParser.ReferenceVersion ? "Product" : "product";
this.OnixParser = ProvidedParser;
// this.OnixReader = OnixLegacyParser.CreateXmlReader(LegacyOnixContent, false, ProvidedParser.PerformValidation);
this.OnixReader = OnixLegacyParser.CreateXmlTextReader(LegacyOnixContent);
ProductSerializer = new XmlSerializer(typeof(OnixLegacyProduct), new XmlRootAttribute(this.ProductXmlTag));
}
public void Dispose()
{
if (this.OnixReader != null)
{
this.OnixReader.Close();
this.OnixReader = null;
}
}
public bool MoveNext()
{
bool bResult = true;
if (this.OnixDoc == null)
{
this.OnixDoc = new XmlDocument();
this.OnixDoc.Load(this.OnixReader);
this.ProductList = this.OnixDoc.GetElementsByTagName(this.ProductXmlTag);
}
if (this.OnixHeader == null)
this.OnixHeader = OnixParser.MessageHeader;
if (++CurrentIndex < this.ProductList.Count)
{
string sInputXml = this.ProductList[CurrentIndex].OuterXml;
try
{
CurrentRecord =
this.ProductSerializer.Deserialize(new StringReader(sInputXml)) as OnixLegacyProduct;
if ((CurrentRecord != null) && OnixParser.AlwaysReturnInputXml)
CurrentRecord.SetInputXml(sInputXml);
if ((CurrentRecord != null) && OnixParser.ShouldApplyDefaults)
CurrentRecord.ApplyHeaderDefaults(this.OnixHeader);
if ((CurrentRecord != null) &&
(CurrentRecord.OnixOtherTextList != null) &&
(CurrentRecord.OnixOtherTextList.Length > 0))
{
int nOTCount = CurrentRecord.OnixOtherTextList.Length;
for (int nIdx = 0; nIdx < OtherTextList.Count; ++nIdx)
{
if (nIdx < nOTCount)
{
OnixLegacyOtherText TempText = CurrentRecord.OnixOtherTextList[nIdx];
TempText.Text = OtherTextList[nIdx];
}
}
}
OtherTextList.Clear();
}
catch (Exception ex)
{
CurrentRecord = new OnixLegacyProduct();
CurrentRecord.SetParsingError(ex);
CurrentRecord.SetInputXml(sInputXml);
}
}
else
bResult = false;
return bResult;
}
public void Reset()
{
return;
}
public object Current
{
get
{
return CurrentRecord;
}
}
}
}