O
OpticTygre
Hey folks,
I'm wondering if I'm doing this the best way...
I want to take an XML file with only Parameters in the nodes, ie: <MyTag
Path='C:\SomePath' FileType='TXT'/> or <MyTag Value1='1' Value2='0'
Value3='6' Value4='1234'/> and capture all the values into an arraylist.
One note to add: The XML files passed into this procedure will have a
static amount of Parameter values, meaning if one tag in the document has 4
values, they all will have 4 values. However, the number of parameter
values may change between XML documents, meaning one document could have an
unknown amount of tags with 4 parameter values each, and another an unknown
amount of tags with 2 parameter values each. I hope this makes sense.
Just curious if there was a better way to do it than this...
Private Function ReadXMLFile(ByVal FilePath As String) As ArrayList(,)
Dim objDocument As New XmlDocument
Dim reader As XmlNodeReader
Dim ArrValues(0, 0) As ArrayList
Dim iCounter As Integer = 0
Dim x As Integer
objDocument.Load(FilePath)
reader = New XmlNodeReader(objDocument)
While reader.Read
If reader.IsStartElement Then
If reader.HasAttributes Then
ReDim Preserve ArrValues(iCounter,
reader.AttributeCount - 1)
For x = 0 To reader.AttributeCount - 1
reader.MoveToAttribute(x)
ArrValues(iCounter, x).Add(reader.Value)
Next
iCounter += 1
End If
End If
End While
Return ArrValues
End Function
I'm wondering if I'm doing this the best way...
I want to take an XML file with only Parameters in the nodes, ie: <MyTag
Path='C:\SomePath' FileType='TXT'/> or <MyTag Value1='1' Value2='0'
Value3='6' Value4='1234'/> and capture all the values into an arraylist.
One note to add: The XML files passed into this procedure will have a
static amount of Parameter values, meaning if one tag in the document has 4
values, they all will have 4 values. However, the number of parameter
values may change between XML documents, meaning one document could have an
unknown amount of tags with 4 parameter values each, and another an unknown
amount of tags with 2 parameter values each. I hope this makes sense.
Just curious if there was a better way to do it than this...
Private Function ReadXMLFile(ByVal FilePath As String) As ArrayList(,)
Dim objDocument As New XmlDocument
Dim reader As XmlNodeReader
Dim ArrValues(0, 0) As ArrayList
Dim iCounter As Integer = 0
Dim x As Integer
objDocument.Load(FilePath)
reader = New XmlNodeReader(objDocument)
While reader.Read
If reader.IsStartElement Then
If reader.HasAttributes Then
ReDim Preserve ArrValues(iCounter,
reader.AttributeCount - 1)
For x = 0 To reader.AttributeCount - 1
reader.MoveToAttribute(x)
ArrValues(iCounter, x).Add(reader.Value)
Next
iCounter += 1
End If
End If
End While
Return ArrValues
End Function