Groups | Blog | Home
all groups > dotnet xml > november 2005 >

dotnet xml : Inherit from XmlDocument?


Gustaf
11/28/2005 5:12:06 PM
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.

Pascal Schmitt
11/28/2005 6:30:40 PM
Hello!

[quoted text, click to view]

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.


--
AddThis Social Bookmark Button