Download Latest Version org.planinternet.simpledom-0.1.0.jar (45.3 kB)
Email in envelope

Get an email when there's a new version of org.planinternet.simpledom

Home
Name Modified Size InfoDownloads / Week
Readme.md 2026-01-09 2.8 kB
org.planinternet.simpledom-0.1.0.jar 2026-01-09 45.3 kB
Totals: 2 Items   48.1 kB 0

Java Package org.planinternet.simpledom

(C) 2025-2026 Roger Schreiter, roger@planinternet.de

Simpledom is a very simple XML (or HTML) parser and builder. Simpledom maps the document object model and provides tools to operate with nodes, parents, children, content, data and attributes. Probably this package is still incomplete and just covers the usage, which it was originally written for. Further features, making simpledom less incomplete, may be added as needed.

Get Releases Packaged in Jar-Files

https://sourceforge.net/projects/org-planinternet-simpledom

Usage

This Java package does not depend on external libraries, which are not commonly part of common Java SDKs.

Example Usage as Parser

import org.planinternet.simpledom.SimpleParser;

public void loadGymNews() {
    String htmlSrc;
    try {
        htmlSrc = new String(Files.readAllBytes(
            Paths.get(PathToSourceFile)
        ));
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    DomNode gymNews;
    try {
        gymNews = SimpleParser.parseDocument(htmlSrc, true);
    } catch (ParseException e) {
        e.printStackTrace();
        return;
    }

    for (DomNode n : gymNews.children) {
        // make anything with DomNode n ...
    }

    DomNode html = gymNews.getElementByTag("html", 0);
    DomNode head = null;
    if (html!=null) head = html.getElementByTag("head", 0);
    DomNode base = null;
    if (head!=null) base = head.getElementByTag("base", 0);
    if (base!=null) stb_base = URI.create(base.getHref());

    gymNews.getAllElementsByTag("div", this::putNewGymArticle);
}


private void putNewGymArticle(DomNode div) {
    if (!div.getClassName().contains("articletype-0")) return;

    DomNode a = div.getFirstElementByTag("a");

    DomNode h = div.getFirstElementByTag("h1");
    String title = h.getText(true);
    ...

For more utility functions for getting data from nodes, see at the end of source file DomNode.java, which is pretty self explaining!

When parsing an XML file, not a HTML file, omit the boolean value when calling method parseDocument or set to false! It is about looking for self closing HTML tags like <br> (which should be written as <br /> in XML).

Example Usage as Builder

DomNode article = DomNode.div()
    .setClasses("newsArticle")
    .appendChild(DomNode.div()
        .setClasses("articleAccountInfo")
        .appendChild(DomNode.img().setSrc(avatarSrc).setClasses("avatarIcon"))
        .appendChild(DomNode.div()
            .appendChild(DomNode.div().setClasses("displayName").appendText(displayName))
            .appendChild(DomNode.div().appendText(accountName))
        )
    );      

Many builder methods return the node itself, for you can daisychain as shown in the above example.

Look for // Chainable HTML-utils in source file DomNode.java, and below you will find the builder functions, which are mostly pretty self explaining.

Source: Readme.md, updated 2026-01-09