1. Those are the contents of Text type Nodes corresponding to the document formating lines.
2. Your implementation of characters method does not recognize the fact that characters may be called multiple times inside the content of a single element if the document is longer than a single input buffer.
raj malhotra wrote:How would i handle it if i want to show only the element name and and its value in the output?
You would use some if-statements which checked to see if the node in question was an Element node. And by the way, in DOM elements don't have values. Perhaps you're thinking of elements which only have a single child node which is a Text node? If you want to get that, then just write code to get the child. But you should be aware that it's possible for an Element node to have more than one child node. This is called "mixed content" and it's a perfectly normal thing to do.