I have a class that contains a certain kind of XML document. The input
file is *not* an XmlDocument, but when loaded, I want it to work like
the XmlDocument class, like:
MyDocument doc = new MyDocument();
doc.Load("input.txt"); // doc is now an XmlDocument
// Query or modify the XmlDocument as usual
doc.Save("output.xml"); // doc saved using XmlDocument.Save();
That is, the input file is not XML, and the Load() method is obviously
not the same, but otherwise the MyDocument class is a copy of
XmlDocument. Can someone please show me what the MyDocument class shall
look like to inherit from XmlDocument? I never did anything like that
before. Not that I don't want to *extend* XmlDocument with my own Load()
method. I want to *replace* all Load() methods with my own.
Gustaf
Pascal Schmitt - 28 Nov 2005 17:30 GMT
Hello!
> That is, the input file is not XML, and the Load() method is obviously
> not the same, but otherwise the MyDocument class is a copy of
> XmlDocument. Can someone please show me what the MyDocument class shall
> look like to inherit from XmlDocument? I never did anything like that
> before. Not that I don't want to *extend* XmlDocument with my own Load()
> method. I want to *replace* all Load() methods with my own.
There is an easier way: inherit from XmlReader. There are overloads for
the XmlDocument.Load, XslTransform.Load and XpathDocument.Load-Methods
that allow you to specify an own XmlReader. Thus you will gain more
flexibility - and it's easier to write it because you only have to parse
the tokens contained in the file and not create the DOM-Tree yourself.

Signature
Pascal Schmitt