GetNodeValue Subroutine

The GetNodeValue subroutine, which the following code illustrates, takes an XML element from the GetLingoValues subroutine and passes it into a loop. First, the loop tests that the element has an attribute named LID. The loop finds the first element that has an LID attribute and passes that element into the AppendAttribs subroutine along with the corresponding node in lingo.xml. The following code fragment illustrates this process.

Private Sub GetNodeValue(ByRef elem As IXMLDOMNode)
   Dim count As Integer
   Dim copyFromNode As IXMLDOMNode
   Dim NodeValue As String
   
   On Error Resume Next
   
    For count = 0 To elem.Attributes.length - 1
    'maps the LID of template file with LID of Lingo file
      If UCase(elem.Attributes(count).nodeName) = "LID" Then
         NodeValue = elem.Attributes(count).NodeValue
         Set copyFromNode = lXML.nodeFromID(NodeValue)
         If Not copyFromNode Is Nothing Then
           Call AppendAttribs(elem, copyFromNode)
         Else
           ASP.Write "<b><i>Error : Missing LID = " & _
                     NodeValue & " in Lingo File. </i></b>.<br>"
           GoTo ErrHandler
         End If
      End If
    Next
    Exit Sub
ErrHandler:
   Err.Raise "Error No: " & Hex(Err.number), "Lingo.GetNodeValue", Err.description
End Sub

Like the GetFiles subroutine, the code uses an instance of the ASP Response object, referenced by the ASP object variable, to communicate errors to the browser. If the code fails to find a LID attribute in the current element, it raises the error and continues with the next element, which prevents the application from crashing.

See NodeFromID vs. SelectSingleNode for a discussion of how this code uses a schema (lingoSchema.xml) to perform a more efficient search for corresponding nodes.