All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.likethesalad.placeholder.utils.XmlUtils.kt Maven / Gradle / Ivy

Go to download

This is a Gradle plugin for Android applications which resolves XML string references in other XML strings.

There is a newer version: 1.3.0
Show newest version
package com.likethesalad.placeholder.utils

import com.likethesalad.placeholder.data.Constants.Companion.XML_STRING_TAG
import com.likethesalad.placeholder.models.StringResourceModel
import org.w3c.dom.Document
import org.w3c.dom.Element
import org.w3c.dom.Node

class XmlUtils {

    companion object {

        fun stringResourceModelToElement(document: Document, stringResourceModel: StringResourceModel): Element {
            val strElement = document.createElement(XML_STRING_TAG)
            strElement.textContent = stringResourceModel.content
            for (it in stringResourceModel.attributes) {
                strElement.setAttribute(it.key, it.value)
            }
            return strElement
        }

        fun nodeToStringResourceModel(node: Node): StringResourceModel {
            val attributesMap = mutableMapOf()
            val attributesNodes = node.attributes
            for (it in 0 until attributesNodes.length) {
                val attr = attributesNodes.item(it)
                attributesMap[attr.nodeName] = attr.textContent
            }
            return StringResourceModel(attributesMap, node.textContent)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy