Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XML node attribute vanishes
Message
From
24/12/2012 04:15:24
 
 
To
24/12/2012 01:06:26
General information
Forum:
ASP.NET
Category:
XML
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01560521
Message ID:
01560525
Views:
75
This message has been marked as the solution to the initial question of the thread.
A guess

Look at the two remarks I added in your code
     // (2) You clear the oXmlNode.Attributes from the previous call ( saved in (1)  )

      //  (1)  You save a reference to  oXmlNode.Attributes
So, if you need oXmlAttributeCollection afterwards

replace
 ' If we have a content
>            If Not oXmlAttributeCollection Is Nothing Then
>                oXmlAttributeCollection.RemoveAll()
>            End If
with
 ' If we have a content
>            If Not oXmlAttributeCollection Is Nothing Then
>                oXmlAttributeCollection = Nothing
>            End If
or
 ' If we have a content
>                oXmlAttributeCollection = Nothing
ps: For better performance, I would at the beginning of the function
  Dim attr as String = UCase(tcAttribute) 
And in the loop use attr instead of UCase(tcAttribute)

>Here is the method I use to get an attribute from a node:
>
>
>        ' Get a XML node attribute
>        ' expC1 Node
>        ' expC2 Attribute
>        Public Function GetXMLNodeAttributeValue(ByVal tcNode As String, ByVal tcAttribute As String) As Boolean
>            Dim llFound As Boolean = False
>            Dim loAttribute As XmlAttribute = Nothing
>
>            ' Reset the values
>            cMessage = ""
>            cNodeAttribute = ""
>

     // (2) You clear the oXmlNode.Attributes from the previous call ( saved in (1)  )
 
>            ' If we have a content
>            If Not oXmlAttributeCollection Is Nothing Then
>                oXmlAttributeCollection.RemoveAll()
>            End If
>
>            ' Select the node
>            If oXmlNameSpaceManager Is Nothing Then
>                oXmlNode = oXmlDocument.SelectSingleNode(tcNode)
>            Else
>                oXmlNode = oXmlDocument.SelectSingleNode(tcNode, oXmlNameSpaceManager)
>            End If
>
>            ' If the node does not exist
>            If oXmlNode Is Nothing Then
>                cMessage = oApp.StrTran(cNodeDoesNotExist, "##Node##", tcNode)
>                Return False
>            End If
>
      //  (1)  You save a reference to  oXmlNode.Attributes


>            ' Assign the new attributes to this object
>            oXmlAttributeCollection = oXmlNode.Attributes
>
>            ' Scan the attribute collection
>            For Each loAttribute In oXmlNode.Attributes
>
>                ' If this is the one
>                If UCase(loAttribute.Name) = UCase(tcAttribute) Then
>                    cNodeAttribute = loAttribute.Value
>                    llFound = True
>                    Exit For
>                End If
>
>            Next
>
>            ' If we did not find it
>            If Not llFound Then
>                cMessage = oApp.StrTran(cAttributeDoesNotExist, "##Attribute##", tcAttribute)
>                Return False
>            End If
>
>            Return True
>        End Function
>
>
>This works well. In fact, it works ok if I call it once. But, lets say I have to call it a second time, from the same oXMLDocument object to retrieve another attribute from the same node. This time, it detects that I have no attribute for the same node.
>
>I have been trying to find what was causing this. If I do not have the line oXmlAttributeCollection.RemoveAll(), it will find it. However, I need that line. I need to clear out the list of attributes for the node before looking up for another attribute using this method again. So, for example, if I have 28 attributes for the last node I used in this method, if I call the same node again but to retrieve another attribute, it will say that I have 0 attribute. If I comment the oXmlAttributeCollection.RemoveAll() line, all is ok. Why is it like that?
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform