parse xml

  • Thread starter Thread starter cle
  • Start date Start date
C

cle

how do I parse an xml file in the cf.
I tried to inherit from xmlElement and add a method to
access directly the xPath expression; why is it impossible
to inherit from the xmlElement??
tia cle
 
As someone answered to me, "The CF doesn't support XPath."
As Rick Spiewak (thanks Rick by the way) posted, here is some helping code:

"Here is a routine I wrote to solve part of this problem. You could modify
it
to return the actual node if you want to update it:



' This function replicates the SelectSingleNode MSXML function only
to the extent required by

' expressions such as /starting/next/next/element or
/starting/next/next/element/@attribute

Public Function SelectSingleNode(ByVal xmldoc As XmlDocument, ByVal
sInput As String) As String

Dim sSelect() As String, sXML As String, i As Integer, xNode As
XmlNode, tNode As XmlNode

' Break down the input string

sSelect = Split(sInput, "/")

If UBound(sSelect) < 1 Then Return ""

' Get the first node

xNode = xmldoc.GetElementsByTagName(sSelect(1)).Item(0)

' go to the next-to-last element

For i = 2 To UBound(sSelect) - 1

If xNode.HasChildNodes Then

For Each tNode In xNode.ChildNodes

If tNode.Name = sSelect(i) Then

xNode = tNode

Exit For

End If

Next

Else

Return ""

End If

Next

' Handle last node or attribute

If Mid(sSelect(i), 1, 1) = "@" Then

If xNode.Attributes(Mid(sSelect(i), 2)) Is Nothing Then

Return ""

Else

Return xNode.Attributes(Mid(sSelect(i), 2)).InnerText

End If

Else

For Each tNode In xNode.ChildNodes

If tNode.Name = sSelect(i) Then

xNode = tNode

Exit For

End If

Next

If xNode Is Nothing Then Return ""

Return xNode.InnerText

End If



End Function

"
 
Back
Top