By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,165 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,165 IT Pros & Developers. It's quick & easy.

XmlDocument Inheritance problem

P: n/a
I have created a class which inherits from XmlDocument.
It works as I expected.
If I use Visual Studio, and type a <carriage return> after
"inherits XmlDocument", VS adds three method overrides.
These seem to make sense, but then the class doesn't
behave as I intended, or as it did if I typed in the data
myself. See example below.

Imports System.xml
Module Module1

Sub Main()
Dim doc1 As New SimpleInheritance
Dim doc2 As New VisualStudioInheritance

End Sub

End Module
Public Class SimpleInheritance
Inherits XmlDocument

Public Sub New()
MyBase.New()
LoadXml("<tag>text</tag>")
Console.WriteLine("SimpleInheritance: " &
OuterXml & "End of text")
End Sub
End Class
Public Class VisualStudioInheritance
Inherits XmlDocument
Public Sub New()
MyBase.New()
LoadXml("<tag>text</tag>")
Console.WriteLine("VisualStudioInheritance: " &
OuterXml & "End of text")

End Sub
Public Overrides Function CloneNode(ByVal deep As
Boolean) As System.Xml.XmlNode

End Function

Public Overrides Sub WriteContentTo(ByVal w As
System.Xml.XmlWriter)

End Sub

Public Overrides Sub WriteTo(ByVal w As
System.Xml.XmlWriter)

End Sub
End Class
I cann't see why the three methods have the effect that
they do. Sure it's obvious, but help would be
appreciated........
Thanks

Robin Hay

Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Having overridden those methods, when the XmlDocument needs to call them for
some reason, nothing will happen. You should be able to just delete those
methods, but if you HAVE to have them, simply add
MyBase.FunctionName(params) (Example: MyBase.CloneNode(w)) to the last line
of the method. Calling the MyBase version of the function tells VB to "do
whatever the function is supposed to do" in addition to what your override
does. I'm rambling, but I hope this makes sense.
"Robin Hay" <ha****@btconnect.com> wrote in message
news:02****************************@phx.gbl...
I have created a class which inherits from XmlDocument.
It works as I expected.
If I use Visual Studio, and type a <carriage return> after
"inherits XmlDocument", VS adds three method overrides.
These seem to make sense, but then the class doesn't
behave as I intended, or as it did if I typed in the data
myself. See example below.

Imports System.xml
Module Module1

Sub Main()
Dim doc1 As New SimpleInheritance
Dim doc2 As New VisualStudioInheritance

End Sub

End Module
Public Class SimpleInheritance
Inherits XmlDocument

Public Sub New()
MyBase.New()
LoadXml("<tag>text</tag>")
Console.WriteLine("SimpleInheritance: " &
OuterXml & "End of text")
End Sub
End Class
Public Class VisualStudioInheritance
Inherits XmlDocument
Public Sub New()
MyBase.New()
LoadXml("<tag>text</tag>")
Console.WriteLine("VisualStudioInheritance: " &
OuterXml & "End of text")

End Sub
Public Overrides Function CloneNode(ByVal deep As
Boolean) As System.Xml.XmlNode

End Function

Public Overrides Sub WriteContentTo(ByVal w As
System.Xml.XmlWriter)

End Sub

Public Overrides Sub WriteTo(ByVal w As
System.Xml.XmlWriter)

End Sub
End Class
I cann't see why the three methods have the effect that
they do. Sure it's obvious, but help would be
appreciated........
Thanks

Robin Hay

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.