Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to implement SelectSingleNode in Compact Framework

1 view
Skip to first unread message

Dan

unread,
Sep 12, 2004, 9:13:25 AM9/12/04
to

I've discovered, to my annoyance, the System.XML.XmlDocument in the compact
framework does not implement either the SelectSingleNode or SelectNodes
method. How do you get around this? Thanks...Dan


Chris Tacke, eMVP

unread,
Sep 12, 2004, 9:21:13 AM9/12/04
to
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

"Dan" <d...@dontspamme.com> wrote in message
news:%23FLJcnM...@TK2MSFTNGP11.phx.gbl...

Dan

unread,
Sep 12, 2004, 10:45:01 AM9/12/04
to
Thanks Chris. I take it that you've had to deal with this problem already?

Dan

"Chris Tacke, eMVP" <ctacke[at]OpenNETCF_dot_org> wrote in message
news:OO3QitMm...@TK2MSFTNGP09.phx.gbl...

Chris Tacke, eMVP

unread,
Sep 12, 2004, 11:53:06 AM9/12/04
to
No, actually SelectSingleNode is usually overkill, a resource hog, and the
XML parser in CF 1.0 is deathly slow. I'd likely use another method (and
manually parse if perf was any kind of requirement). It's just a snippet I
picked up elsewhere with the intent of integrating it into the SDF. I've
got SelectNodes somewhere too.

-Chris

"Dan" <d...@dontspamme.com> wrote in message

news:u0kCoaNm...@TK2MSFTNGP10.phx.gbl...

0 new messages