Xoxo is a simple wrapper around org.w3c.dom to parse XML using nice Kotlin APIs

Related tags

Kotlin Projects Xoxo
Overview

Xoxo 😘

Xoxo is a simple wrapper around org.w3c.dom to parse XML using nice Kotlin APIs. No more NodeList, .item(), etc... just use .children, .filterIsInstance<>() and all the Okio and Kotlin APIs we all love 💙 .

Xoxo is designed for dynamic parsing in small JVM-only projects like Kotlin scripts and does not pretend to cover the full XML specification nor XML editing.

Installation

@file:DependsOn("net.mbonnin.xoxo:xoxo:0.2")

Read the text content of the first
tag in a HTML file

File("index.html").toXmlDocument()
    .root
    .childElements
    .first { it.name == "body" }
    .childElements
    .first { it.name == "div" }
    .textContent

Find all elements with a "videoId" attribute and display their duration

30:30 31:00 """.trimIndent() xmlString.toXmlDocument() .root .walkElements() .filter { it.attributes.containsKey("videoId") } .forEach { println(it.attributes["title"]) println("duration:" + it.childElements.single().textContent) }">
val xmlString = """
    
        
            
                30:30
            
            
                31:00
            
        
    
""".trimIndent()

xmlString.toXmlDocument()
    .root
    .walkElements()
    .filter { it.attributes.containsKey("videoId") }
    .forEach {
        println(it.attributes["title"])
        println("duration:" + it.childElements.single().textContent)
    }
You might also like...
Service exposes sensitive administration APIs to initialize and set lower level of Slurpanize infrastructure

slurpanize-baker Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, please visit its

Exploring google's new android APIs

Exploring New android APIs 1. New Splash Screen API in Android 12 Starting in Android 12, the launch animation for all apps when running on a device w

Katbox - Kotlin wrapper for catbox.moe and litterbox.catbox.moe

katbox katbox is a Kotlin multiplatform wrapper written with ktor and coroutines

Katoot - An easy-to-use (blocking) Kotlin wrapper for Kahoot's REST api

katoot An easy-to-use (blocking) Kotlin wrapper for Kahoot's REST api. Usage Qui

Asynchronous Spring Initializr API wrapper for Kotlin/JVM

initializr-kt Asynchronous Spring Initializr API wrapper for Kotlin/JVM. This library provides the simplest DSL for initializing Spring Boot projects

Extensive Redis Pub-Sub wrapper for lettuce written in Kotlin

aware Extensive annotation-based Redis Pub-Sub wrapper for lettuce written in Kotlin. Aware was written to be a replacement for the very dated Banana

This is a sample app to demonstrate the power of using EventSourced models and the ease with which these can be modelled using Kotlin.
This is a sample app to demonstrate the power of using EventSourced models and the ease with which these can be modelled using Kotlin.

Lego 4 Rent This is a sample app to demonstrate the power of using EventSourced models and the ease with which these can be modelled using Kotlin. To

A complete Kotlin application built to demonstrate the use of Modern development tools with best practices implementation using multi-module architecture developed using SOLID principles
A complete Kotlin application built to demonstrate the use of Modern development tools with best practices implementation using multi-module architecture developed using SOLID principles

This repository serves as template and demo for building android applications for scale. It is suited for large teams where individuals can work independently on feature wise and layer wise reducing the dependency on each other.

A simple ToDo Task Manager App made in Kotlin using Room DataBase.
A simple ToDo Task Manager App made in Kotlin using Room DataBase.

ToDo List App 🌟 About A simple To-Do List Management App that helps you get things done. Built with Kotlin, it helps the user to add their task. User

Comments
  • Remove unsafe `asElement` and `asText` dynamic getters

    Remove unsafe `asElement` and `asText` dynamic getters

    These will crash if the object is not of the right type, and if we need to know the type to prevent crash, we can already do

    fun test(node: XmlNode) {
        val element = node as? XmlElement
        val text = node as? XmlText
        TODO()
    }
    

    Instead, we should encourage the idiomatic usage of smart cast allowed by the sealed interface.

    fun test(document: XmlDocument) {
        document.root.walk().map {
            when (it) {
                is XmlElement -> TODO()
                is XmlText -> TODO()
            }
        }
    }
    

    Unless you had something specific in mind for these extensions.

    opened by SimonMarquis 4
Releases(v0.3)
  • v0.3(Jun 11, 2022)

    What's Changed

    • Fix license url with /blob path prefix by @SimonMarquis in https://github.com/martinbonnin/Xoxo/pull/1
    • Replace intermediate map operator into joinToString by @SimonMarquis in https://github.com/martinbonnin/Xoxo/pull/2
    • Don't print empty attributes map in XmlElement.toString() by @SimonMarquis in https://github.com/martinbonnin/Xoxo/pull/4
    • Replace current ordering with a more natural "Depth First" by @SimonMarquis in https://github.com/martinbonnin/Xoxo/pull/5
    • Fix StringIndexOutOfBoundsException by @SimonMarquis in https://github.com/martinbonnin/Xoxo/pull/3
    • filter(predicate).first() can be simplified with first(predicate) by @SimonMarquis in https://github.com/martinbonnin/Xoxo/pull/6
    • add Any?.cast() by @martinbonnin in https://github.com/martinbonnin/Xoxo/pull/8

    New Contributors

    • @SimonMarquis made their first contribution in https://github.com/martinbonnin/Xoxo/pull/1
    • @martinbonnin made their first contribution in https://github.com/martinbonnin/Xoxo/pull/8

    Full Changelog: https://github.com/martinbonnin/Xoxo/commits/v0.3

    Source code(tar.gz)
    Source code(zip)
Owner
Martin Bonnin
Make val, not var
Martin Bonnin
Basic application that uses Retrofit, Moshi and Coil libraries to parse data from web API

DogAlbum_Api_CodeThrough Basic application that uses Retrofit, Moshi and Coil libraries to parse data from web API This folder contains the completed

Ayana Bando 0 Nov 9, 2021
Nice and simple DSL for Espresso Compose UI testing in Kotlin

Kakao Compose Nice and simple DSL for Espresso Compose in Kotlin Benefits Readability Reusability Extensible DSL How to use it Create Screen Create yo

null 74 Dec 26, 2022
Nice String in Kotlin

Nice String We'll say a string is nice if at least two of the following conditio

Bunyod Rafikov 0 Dec 28, 2021
Flexible switch is a responsive switch with some nice features which developers can use for making awesome switches on android platform.

flexible-switch It is a responsive switch in android, it can resize itself according to its size. It's recommended to use it with ConstraintLayout to

Coders Route 5 Dec 20, 2022
In this Repo i create public apis to serve apps, like muslim apps using Spring, kotlin, and microservices

spring-freelance-apis-kotlin In this Repo i create public apis to serve apps, like muslim apps using Spring, kotlin, and microservices This repo for l

null 6 Feb 13, 2022
Plugin and Desktop app for parsing layout xml into Composable code

composed-xml Inspired by - Recompose composed-xml is a tool for parsing Android layouts into Jetpack Compose code. It can work as both Desktop app or

Bacho Kurtanidze 9 Dec 26, 2022
MMKV for Kotlin Multiplatform is a wrapper for MMKV using Kotlin API

MMKV for Kotlin Multiplatform is a wrapper for MMKV using Kotlin API

Ctrip, Inc. 65 Dec 29, 2022
An Android application for browsing video games and checking the latest gaming news from around the world.

Gamedge An Android application for browsing video games and checking the latest gaming news from around the world. Built entirely using the Jetpack Co

Paul Rybitskyi 602 Dec 25, 2022
Simple api wrapper for nekos.life

nekos-kt Simple api wrapper for nekos.life Installation Maven: <repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url>

cattyn 6 Oct 24, 2022