A short bit of the code I'm using to read an xml file.
I want to create two arraylists with each cell of the arraylist filled with a string that is an element and all its child nodes.
Problem is it will only read the first element list and misses the next one completely. If I comment out the first one it will read the list it misses out.
I've looked at the code in the debugger and find out it doesn't pick up the Name of the second list, but the element after it. For instance it should be <supplies>, but it misses it out and reads <supplyli> instead.
Anyone know why this should be?
While reader.Read()
If reader.NodeType = XmlNodeType.Element Then
Select Case reader.Name
Case "supequip"
' Read in all the child nodes - the list
tReader = New XmlTextReader(New StringReader(reader.ReadOuterXml()))
While tReader.Read()
If tReader.Name = "supequi" Then
While tReader.Name = "supequi"
supEqList.Add(tReader.ReadOuterXml())
End While
End If
End While
Case "supplies"
' Read in all the child nodes - the list
tReader = New XmlTextReader(New StringReader(reader.ReadOuterXml()))
While tReader.Read()
If tReader.Name = "supply" Then
While tReader.Name = "supply"
consumableList.Add(tReader.ReadOuterXml())
End While
End If
End While
End Select
End If
End While
the results I want...
supEqList =
0: <supequi id="se0001"><nomen>5119-001 - Torque Wrench</nomen><csnref refcsn="TBD" refisn="TBD"></csnref><qty uom="EA">1</qty></supequi>
1: <supequi id="se0002"><nomen>5012-004 - Twist Drill</nomen><csnref refcsn="TBD"refisn="TBD"></csnref><qty uom="EA">1</qty></supequi>
etc..
consumableList =
0: <supply id="su0001"><nomen>LCM06-028 - Molykote MS44 Grease</nomen><csnref refcsn="ZC0026-030-001" refisn="00A"></csnref><qty>AR</qty></supply>
1: <supply id="su0003"><nomen>O-ring</nomen><csnref refcsn="ZC0026-020-003" refisn="00A"></csnref><qty uom="EA">1</qty></supply>
etc...
All I get is the SupEqList.
A fragment of the file with the relevant elements
></perskill></reqpers><supequip
><supeqli
><supequi
id="se0001"
><nomen
>5119-001 - Torque Wrench</nomen><csnref
refcsn="TBD"
refisn="TBD"
></csnref><qty
uom="EA"
>1</qty></supequi><supequi
id="se0002"
><nomen
>5012-004 - Twist Drill</nomen><csnref
refcsn="TBD"
refisn="TBD"
></csnref><qty
uom="EA"
>1</qty></supequi></supeqli></supequip><supplies
><supplyli
><supply
id="su0001"
><nomen
>LCM06-028 - Molykote MS44 Grease</nomen><csnref
refcsn="ZC0026-030-001"
refisn="00A"
></csnref><qty
>AR</qty></supply><supply
id="su0003"
><nomen
>O-ring</nomen><csnref
refcsn="ZC0026-020-003"
refisn="00A"
></csnref><qty
uom="EA"
>1</qty></supply><supply
id="su0004"
><nomen
>O-ring</nomen><csnref
refcsn="ZC0026-020-005"
refisn="00A"
></csnref><qty
uom="EA"
>1</qty></supply><supply
id="su0005"
><nomen
>Spacer</nomen><csnref
refcsn="ZC0026-020-006"
refisn="00A"
></csnref><qty
uom="EA"
>1</qty></supply></supplyli></supplies><spares
><nospares
I want to create two arraylists with each cell of the arraylist filled with a string that is an element and all its child nodes.
Problem is it will only read the first element list and misses the next one completely. If I comment out the first one it will read the list it misses out.
I've looked at the code in the debugger and find out it doesn't pick up the Name of the second list, but the element after it. For instance it should be <supplies>, but it misses it out and reads <supplyli> instead.
Anyone know why this should be?
While reader.Read()
If reader.NodeType = XmlNodeType.Element Then
Select Case reader.Name
Case "supequip"
' Read in all the child nodes - the list
tReader = New XmlTextReader(New StringReader(reader.ReadOuterXml()))
While tReader.Read()
If tReader.Name = "supequi" Then
While tReader.Name = "supequi"
supEqList.Add(tReader.ReadOuterXml())
End While
End If
End While
Case "supplies"
' Read in all the child nodes - the list
tReader = New XmlTextReader(New StringReader(reader.ReadOuterXml()))
While tReader.Read()
If tReader.Name = "supply" Then
While tReader.Name = "supply"
consumableList.Add(tReader.ReadOuterXml())
End While
End If
End While
End Select
End If
End While
the results I want...
supEqList =
0: <supequi id="se0001"><nomen>5119-001 - Torque Wrench</nomen><csnref refcsn="TBD" refisn="TBD"></csnref><qty uom="EA">1</qty></supequi>
1: <supequi id="se0002"><nomen>5012-004 - Twist Drill</nomen><csnref refcsn="TBD"refisn="TBD"></csnref><qty uom="EA">1</qty></supequi>
etc..
consumableList =
0: <supply id="su0001"><nomen>LCM06-028 - Molykote MS44 Grease</nomen><csnref refcsn="ZC0026-030-001" refisn="00A"></csnref><qty>AR</qty></supply>
1: <supply id="su0003"><nomen>O-ring</nomen><csnref refcsn="ZC0026-020-003" refisn="00A"></csnref><qty uom="EA">1</qty></supply>
etc...
All I get is the SupEqList.
A fragment of the file with the relevant elements
></perskill></reqpers><supequip
><supeqli
><supequi
id="se0001"
><nomen
>5119-001 - Torque Wrench</nomen><csnref
refcsn="TBD"
refisn="TBD"
></csnref><qty
uom="EA"
>1</qty></supequi><supequi
id="se0002"
><nomen
>5012-004 - Twist Drill</nomen><csnref
refcsn="TBD"
refisn="TBD"
></csnref><qty
uom="EA"
>1</qty></supequi></supeqli></supequip><supplies
><supplyli
><supply
id="su0001"
><nomen
>LCM06-028 - Molykote MS44 Grease</nomen><csnref
refcsn="ZC0026-030-001"
refisn="00A"
></csnref><qty
>AR</qty></supply><supply
id="su0003"
><nomen
>O-ring</nomen><csnref
refcsn="ZC0026-020-003"
refisn="00A"
></csnref><qty
uom="EA"
>1</qty></supply><supply
id="su0004"
><nomen
>O-ring</nomen><csnref
refcsn="ZC0026-020-005"
refisn="00A"
></csnref><qty
uom="EA"
>1</qty></supply><supply
id="su0005"
><nomen
>Spacer</nomen><csnref
refcsn="ZC0026-020-006"
refisn="00A"
></csnref><qty
uom="EA"
>1</qty></supply></supplyli></supplies><spares
><nospares