TunaAdmiral
MIS
Hi!
I wrote a VB.NET program that reads in an XML file, and spits out a text file consisting of every node in the document. For example:
<ROOT>
<NEWRECORD>
<HEADER>
<ADDRESS1>123 Pond Path</ADDRESS1>
<ADDRESS2>Buffalo, NY 13213</ADDRESS2>
<ADDRESS3></ADDRESS3>
</HEADER>
<TOTALS>
<QUANTITY>250</QUANTITY>
<OPTIONALWARRANTY></OPTIONALWARRANTY>
<PRICE>775.23</PRICE>
</TOTALS>
</NEWRECORD>
</ROOT>
becomes:
<NEWRECORD>
<HEADER>
ADDRESS1: 123 Pond Path
ADDRESS2: Buffalo, NY 13213
ADDRESS3:
<TOTALS>
QUANTITY: 250
OPTIONALWARRANTY:
PRICE: 775.23
The application that reads in this text file(A third party, COBOL based app), needs to know the exact line of each item, relative to the each occurence of the <NEWRECORD> line. So, in the example shown above, the application assumes that ADDRESS2 will always appear 3 lines after an instance of <NEWRECORD>.
Not an ideal situation, I know.
This system completely breaks down if I receive an XML file with an inconsistent number of Address Lines.
For example:
<NEWRECORD>
<HEADER>
<ADDRESS1>123 Pond Path</ADDRESS1>
<ADDRESS2>Buffalo, NY 13213</ADDRESS2>
<ADDRESS3></ADDRESS3>
</HEADER>
.....NEXT RECORD.....
<NEWRECORD>
<HEADER>
<ADDRESS1>654 State St.</ADDRESS1>
<ADDRESS2>456 Division St.</ADDRESS2>
<ADDRESS3>156 Lodi St.</ADDRESS3>
<ADDRESS4>987 Tulip Ave.</ADDRESS4>
<HEADER>
So now the output would look something like this:
<NEWRECORD>
<HEADER>
ADDRESS1: 123 Pond Path
ADDRESS2: Buffalo, NY 13213
ADDRESS3:
....NEXT RECORD....
<HEADER>
ADDRESS1: 654 State St.
ADDRESS2: 456 Division St.
ADDRESS3: 156 Lodi St.
ADDRESS4: 987 Tulip Ave.
What is the best way to deal with an inconsistency like this? Is there a generic way to handle this, or will I have to programmatically check for the existence of specific ADRESSS# nodes when I'm processing the XML file?
Any direction would be appreciated.
- Mikeymac
I wrote a VB.NET program that reads in an XML file, and spits out a text file consisting of every node in the document. For example:
<ROOT>
<NEWRECORD>
<HEADER>
<ADDRESS1>123 Pond Path</ADDRESS1>
<ADDRESS2>Buffalo, NY 13213</ADDRESS2>
<ADDRESS3></ADDRESS3>
</HEADER>
<TOTALS>
<QUANTITY>250</QUANTITY>
<OPTIONALWARRANTY></OPTIONALWARRANTY>
<PRICE>775.23</PRICE>
</TOTALS>
</NEWRECORD>
</ROOT>
becomes:
<NEWRECORD>
<HEADER>
ADDRESS1: 123 Pond Path
ADDRESS2: Buffalo, NY 13213
ADDRESS3:
<TOTALS>
QUANTITY: 250
OPTIONALWARRANTY:
PRICE: 775.23
The application that reads in this text file(A third party, COBOL based app), needs to know the exact line of each item, relative to the each occurence of the <NEWRECORD> line. So, in the example shown above, the application assumes that ADDRESS2 will always appear 3 lines after an instance of <NEWRECORD>.
Not an ideal situation, I know.
This system completely breaks down if I receive an XML file with an inconsistent number of Address Lines.
For example:
<NEWRECORD>
<HEADER>
<ADDRESS1>123 Pond Path</ADDRESS1>
<ADDRESS2>Buffalo, NY 13213</ADDRESS2>
<ADDRESS3></ADDRESS3>
</HEADER>
.....NEXT RECORD.....
<NEWRECORD>
<HEADER>
<ADDRESS1>654 State St.</ADDRESS1>
<ADDRESS2>456 Division St.</ADDRESS2>
<ADDRESS3>156 Lodi St.</ADDRESS3>
<ADDRESS4>987 Tulip Ave.</ADDRESS4>
<HEADER>
So now the output would look something like this:
<NEWRECORD>
<HEADER>
ADDRESS1: 123 Pond Path
ADDRESS2: Buffalo, NY 13213
ADDRESS3:
....NEXT RECORD....
<HEADER>
ADDRESS1: 654 State St.
ADDRESS2: 456 Division St.
ADDRESS3: 156 Lodi St.
ADDRESS4: 987 Tulip Ave.
What is the best way to deal with an inconsistency like this? Is there a generic way to handle this, or will I have to programmatically check for the existence of specific ADRESSS# nodes when I'm processing the XML file?
Any direction would be appreciated.
- Mikeymac