急VB.NET中用XmlReader读取XML文件的指定节点 在线等
发布网友
发布时间:2022-04-29 12:47
我来回答
共1个回答
热心网友
时间:2022-04-27 13:33
没把结果转为二维数组,我把节点放到arraylist里了,里面的每个项都是一个一维数组,其中第一个元素是data的属性,后面存放的是节点的子节点的内容。Dim
xmlreader
As
XmlReader
=
XmlReader.Create("xml.xml")
Dim
alst
As
System.Collections.ArrayList
=
New
System.Collections.ArrayList()
Dim
a()
As
String
=
Nothing
Dim
i
As
Integer
=
0
While
(xmlreader.Read())
If
(xmlreader.NodeType
=
XmlNodeType.Element)
Then
Select
Case
(xmlreader.LocalName)
Case
"data":
If
(a
<>
Nothing)
Then
alst.Add(a)
Redim
a(9)
i
=
0
xmlreader.MoveToFirstAttribute()
a(i)
=
xmlreader.Value
i
+=
1
Case
"cloudcover",
"seeing",
"transparency",
"lifted_index",
"rh2m",
"wind10m_direction",
"wind10m_speed",
"temp2m",
"prec_type":
a(i)
=
xmlreader.ReadString
i
+=
1
End
Select
End
If
Wend
alst.Add(a)
xmlreader.Close() 其实你这个文件用xmldoucment操作方便,为什么要用xmlreader呢?