读取XML文件

下面是读取XML文件的一个实例,pFCDirectory为full path的xml文件.

Private Function RetrieveFeactureClassName() As String()
    
    
Dim xml_document As DOMDocument
    
Set xml_document = New DOMDocument
    
    
Dim fcList() As String
    
Dim i As Integer
    i 
= 0
    
    
If xml_document.Load(pFCDirectory) = True Then
    
        
If xml_document.documentElement Is Nothing Then
        
MsgBox "feature class file empty"
        
Exit Function
        
End If
        
         
Dim rootNode As IXMLDOMNode
         
Set rootNode = xml_document.childNodes.Item(0)
    
        
Dim pFeatDsNodeList As IXMLDOMNodeList
        
Dim pFeatClsNodeList As IXMLDOMNodeList
        
        
Set pFeatDsNodeList = rootNode.childNodes
        pFeatDsNodeList.Reset
    
        
Dim pFeatDsNode As IXMLDOMNode
        
Dim pFeatClsNode As IXMLDOMNode
        
        
Set pFeatDsNode = pFeatDsNodeList.nextNode
        
Do While Not pFeatDsNode Is Nothing
            
            
If pFeatDsNode.hasChildNodes = True Then
                         
                
Set pFeatClsNodeList = pFeatDsNode.childNodes
                pFeatClsNodeList.Reset
                                        
                
Set pFeatClsNode = pFeatClsNodeList.nextNode
                            
                
Do While Not pFeatClsNode Is Nothing
                    
ReDim Preserve fcList(i)
                    fcList(i) 
= pFeatClsNode.Text
                    i 
= i + 1
                    
Set pFeatClsNode = pFeatClsNodeList.nextNode
                
Loop
                
Set pFeatDsNode = pFeatDsNodeList.nextNode
            
End If
        
Loop
           RetrieveFeactureClassName 
= fcList
  
    
Else
        
MsgBox "feature class file not found."
         
Exit Function
    
End If
   

End Function

 

posted on 2009-04-23 09:35  炜升  阅读(235)  评论(0编辑  收藏  举报