Results 1 to 12 of 12

Thread: XML Parsing Question

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    4

    Question XML Parsing Question

    Hey Everyone, I'm trying to make a program that parses XML data and puts it into Text Boxes.

    I've gotten it all coded and don't get any error messages, but I always get "???" displayed in my text boxes. I can't figure out what I coded wrong.

    Please Help! I need to have this figured out by tomorrow.

    Here's the code:
    Code:
    Option Explicit
    
    Dim xml_document As New DOMDocument60
    Dim value_node As IXMLDOMNode
    Dim objX As New MSXML2.DOMDocument60
    Dim parentNode As IXMLDOMNode
    Dim strFileRoot As String
    
    Private Sub LoadValue(xmlDoc As String)
    xml_document.Load xmlDoc
    If xml_document.documentElement Is Nothing Then
    Dim strErrText As String
    Dim xPE As MSXML2.IXMLDOMParseError
    Set xPE = objX.parseError
    With xPE
    strErrText = "Your XML Document failed to load" & _
    "due to the following error." & vbCrLf & _
    "Error #:" & .errorCode & ":" & .reason & _
    "Line #:" & .Line & vbCrLf & _
    "Line Position" & .linepos & vbCrLf & _
    "Position in File:" & .filepos & vbCrLf & _
    "Source Text:" & .srcText & vbCrLf & _
    "Document URL:" & .url
    End With
    MsgBox strErrText, vbExclamation
    End If
    End Sub
    
    Private Sub setRoot(rootElement As String)
    Set parentNode = xml_document.selectSingleNode(rootElement)
    End Sub
    
    Private Function GetNodeValue(ByVal start_at_node As IXMLDOMNode, _
    ByVal node_name As String, _
    Optional ByVal default_value As String) _
    As String
    
    Set value_node = start_at_node.selectSingleNode(".//" & node_name)
    If value_node Is Nothing Then
    GetNodeValue = default_value
    Else
    GetNodeValue = value_node.Text
    End If
    End Function
    
    Private Sub cmdSelectXML_Click()
    
    Dim strFileName As String
    
    
    objX.async = False
    
    CDL.Filter = "XML file (*.xml)|*.xml"
    CDL.DialogTitle = "Select the XML file"
    CDL.ShowOpen
    strFileName = CDL.FileName
    
    Screen.MousePointer = vbHourglass
    
    LoadValue (strFileName)
    setRoot "Dimap_Document"
    txtIDNumber.Text = GetNodeValue(parentNode, "Dataset_ID", "???")
    txtLatLong1.Text = GetNodeValue(parentNode, "Dataset_ID", "???")
    txtLatLong2.Text = GetNodeValue(parentNode, "Dataset_ID", "???")
    txtLatLong3.Text = GetNodeValue(parentNode, "Dataset_ID", "???")
    txtLatLong4.Text = GetNodeValue(parentNode, "Dataset_ID", "???")
    txtScene.Text = GetNodeValue(parentNode, "Dataset_ID", "???")
    txtHoriz.Text = GetNodeValue(parentNode, "Horizontal_CS_Type", "???")
    
    Screen.MousePointer = vbDefault
    Set objX = Nothing
    
    Exit Sub
    
    
    End Sub
    Last edited by Hack; Feb 13th, 2008 at 08:03 AM. Reason: Added Code Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width