C++ HTML Code Parser for generating Parent Child Relation based on Space Hierarchy
This is a simple parser. It provides details about parent child relation by parsing spaces on tags. The input for the program is a text file containing html tags separated by space based on their relation of html syntax. For example,
1 2 3 4 5 6 7 8 | <html> <head> <title></title> </head> <body> <div></div> </body> </html>
|
No need to count the closing tag. The code above is translated to input ( by user ) for the program as,
1 2 3 4 5 | html head title body div
|
In a future post I will convert the space based html hierarchy to proper html tags and vise versa.
Execution:
Sample Input:
1 2 3 4 5 6 7 8 9 10 11 | html head title link body div h1 h2 span aside a
|
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | head is the 1 th child of html title is the 2 th child of html link is the 2 th child of html body is the 1 th child of html div is the 2 th child of html h1 is the 3 th child of html h2 is the 3 th child of html span is the 3 th child of html aside is the 2 th child of html a is the 3 th child of html title is the 1 th child of head link is the 1 th child of head div is the 1 th child of body h1 is the 2 th child of body h2 is the 2 th child of body span is the 2 th child of body aside is the 1 th child of body a is the 2 th child of body h1 is the 1 th child of div h2 is the 1 th child of div span is the 1 th child of div a is the 1 th child of aside
|
Cpp Program Code:
Make sure
input.txt is in the same directory as cpp code file. Also the code can output to text file. Just uncomment the commented freopen in which case it will write to file instead of showing in console.
No comments :
Post a Comment