How to parse HTML <div> tag from scratch without using any library in java

Viewed 118

I want to parse particular div tag's all inner elements in java

For Example: Consider a given HTML code are String. If I parse <div id="6"> in below code it will be get all inner tags include sub div tags. How can I write code without using any library. Using only String methods.

<div id="1">
    <div id ="2">
        <span id="3">
        </span>
        <div id="4">
            <div id="5">
            </div>
        </div>
    </div>
    <div id="6">
        <img id="7" />
        <input id="8" />
        <br id="9" />
        <span id="10">
            <div id="11">
                <div id="12">
                </div>
            </div>
        </span>
        <div id="13">
            <pre id="14">
            </pre>
        </div>
        <span id= "15">
        </span>
    </div>
</div>

Pls share your ideas and any resources for reference.

1 Answers

The div tag is known as Division tag. The div tag is used in HTML to make divisions of content in the web page like (text, images, header, footer, navigation bar, etc). Div tag has both open() and closing () tag and it is mandatory to close the tag. The Div is the most usable tag in web development because it helps us to separate out data in the web page and we can create a particular section for particular data or function in the web pages.

CHECK THIS OUT https://www.geeksforgeeks.org/div-tag-html/

Related