I’ve assigned the task to create a class structure for an xml reader! What I’ve got so far is that there are two main classes for a simple xml file. elements and attributes.I can use the inbuilt c# xml reader to read a xml file! but my code should be able to identify the xml elements, there structure,as well as the attributes.. I’ve so far identified the main two classes but I’m stuck on this now. if some one can explain a possible theory or a method since I’m new to programming, that would be appreciated.
Share
There is a difference between a XML reader and a XML document.
They are modeled after different patterns.
The reader in .NET is made just to read a stream and stop when it encounters some element / attribute or other type of node. This may be practical if you want to be fast or you have a large stream that you don’t want to keep in memory.
The XML document reads the entire stream and instantiates an object model that represents it.
This is practical if the you need to know the structure and it fits into memory.
If you are to implement the reader you could crate methods like ReadNext() which would read and return the next node it finds. For starters I would stick with parsing xml elements and their attributes, not comments, namespaces and other more difficult things.