VB读取xml
xml路径:app.path&"\Data.xml"xml文件内容如下##################################################...
xml路径:app.path & "\Data.xml"
xml文件内容如下
#######################################################
<?xml version="1.0"?>
<i>
<i y="-69" x="-30" delay="180" image="walk1_0.png"/>
<i y="-69" x="-30" delay="180" image="walk1_1.png"/>
<i y="-69" x="-30" delay="180" image="walk1_2.png"/>
<i y="-69" x="-30" delay="180" image="walk1_3.png"/>
........
.......
<i y="-68" x="-33" delay="250" image="XXXX_X.png"/>
</i>
########################################################
写一个函数,把上面的xml内容存入下面四个空维数组里就好了。。。
Dim strImage() As String
Dim strDelay() As String
Dim strX() As String
Dim strY() As String 展开
xml文件内容如下
#######################################################
<?xml version="1.0"?>
<i>
<i y="-69" x="-30" delay="180" image="walk1_0.png"/>
<i y="-69" x="-30" delay="180" image="walk1_1.png"/>
<i y="-69" x="-30" delay="180" image="walk1_2.png"/>
<i y="-69" x="-30" delay="180" image="walk1_3.png"/>
........
.......
<i y="-68" x="-33" delay="250" image="XXXX_X.png"/>
</i>
########################################################
写一个函数,把上面的xml内容存入下面四个空维数组里就好了。。。
Dim strImage() As String
Dim strDelay() As String
Dim strX() As String
Dim strY() As String 展开
2个回答
展开全部
Private Sub Command1_Click()
Dim xmldoc As Object
Set xmldoc = CreateObject("msxml2.domdocument") 'xmlDocment对象
xmldoc.async = False '同步载入方式
xmldoc.Load "C:\sample.xml" '载入xml文件
Dim Root As Object
Set Root = xmldoc.documentElement '获取根结点
Dim arU As Integer
arU = Root.childNodes.length - 1 '根结点的子结点数-1为数组下标
Dim strImage() As String
Dim strDelay() As String
Dim strX() As String
Dim strY() As String
'定义数组下标量
ReDim strImage(arU)
ReDim strDelay(arU)
ReDim strX(arU)
ReDim strY(arU)
Dim i As Integer
Dim C As Object
'获取每个子结点的属性值
For Each C In Root.childNodes
strImage(i) = C.Attributes.getNamedItem("image").Text
strDelay(i) = C.Attributes.getNamedItem("delay").Text
strX(i) = C.Attributes.getNamedItem("x").Text
strY(i) = C.Attributes.getNamedItem("y").Text
i = i + 1
Next
'显示数组内容
Print Join(strImage, vbCrLf)
Print Join(strDelay, vbCrLf)
Print Join(strX, vbCrLf)
Print Join(strY, vbCrLf)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询