none
Is it possible to inherit from XMLNode

    Question

  • I'm trying to create an application that stores and handles all it's data in XML. I was trying to inherit from XmlNode and I get the error message "The type 'System.Xml.XmlNode' has no constructors defined"

    I'm guessing this is because the constructor for XmlNode is private or internal. Is there a way to inherit from XmlNode.
    Saturday, November 26, 2005 8:51 AM

Answers

  • After taking sometime to look at the System.Xml in the object browser I was able to figure out that, if fact, you CANNOT inherit from XmlNode as ALL it's constructors are internal or private.

    You can  on the other hand inherit from XmlElement. XmlElement has a protected internal constructor XmlElement(string prefix, string localname, string namespaceURI, XmlDocument doc) thats can be used in deriving a child class.

    For me XmlElement turned out to be a better choice to derive my classes from.

    Monday, November 28, 2005 7:00 AM

All replies

  • After taking sometime to look at the System.Xml in the object browser I was able to figure out that, if fact, you CANNOT inherit from XmlNode as ALL it's constructors are internal or private.

    You can  on the other hand inherit from XmlElement. XmlElement has a protected internal constructor XmlElement(string prefix, string localname, string namespaceURI, XmlDocument doc) thats can be used in deriving a child class.

    For me XmlElement turned out to be a better choice to derive my classes from.

    Monday, November 28, 2005 7:00 AM
  • This info is quite helpful to me.

    However How do I assaign an existing XmlNode and/or XmlElement object to my customized XmlElement object

    public class MyNode : XmlElement
    {
     public MyNode( string prefix, string localName, string namespaceURI, XmlDocument doc )
    :base( prefix, localName, namespaceURI, doc )
    }
    ...
    MyNode   myNode = (MyNode)SomeXmlNode;

    When I try this, I get a cast error when assigning .  The compiler won't let me define a explicit cast.

    What am I missing here.


    Brent Rogers I.S.P.

    Thursday, April 19, 2012 2:24 PM