Note: This answer was written before the user explained that the XML was not well formed. I'm leaving it here as it may possibly help others.
XMLStarlet is able to produce the element structure of XML documents:
$ xml el file.xml note note/to note/from note/heading note/body
This is different from your expected output, but may be enough for what you want to achieve.
It is also able to convert the XML to PYX, which shows the opening and closing tags on separate lines:
$ xml pyx file.xml (note -\n (to -Tove )to -\n (from -Jani )from -\n (heading -Reminder )heading -\n (body -Don't forget me this weekend! )body -\n )note
From this, it's easy to get exactly the output you are after:
$ xml pyx file.xml | sed -n -e 's/^(//p' -e 's/^)/\//p'| nl 1 note 2 to 3 /to 4 from 5 /from 6 heading 7 /heading 8 body 9 /body 10 /note
The sed instructions removes lines not starting with either ( or ) and replaces these characters according to how you specified it in the question. The nl utility puts line number on lines.
XMLStarlet is sometimes installed as xmlstarlet rather than xml.
<note> <to><to_1><to_1_1>to_child1_1</to_1_1><to_1_2>to_child2_2</to_1_2></to_1><to_2>to_child2</to_2></to> <from>Jani</from><heading>Reminder</heading></note>What should be the 5th node in such case?