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

nosi.core.xml.DomXML Maven / Gradle / Ivy

Go to download

IGRP Framework is a powerful and highly customizable platform developed by the Operational Nucleus for the Information Society (NOSi) to create web applications, it provides out of box, several modules to make easy to create stand-alone, production-grade web applications: authentication and access-control, business processes automation, reporting, page builder with automatic code generation and incorporation of the Once-Only-Principle, written in Java. IGRP Framework WAR - Contains some keys resources that give UI to IGRP Framework and others supports files.

There is a newer version: 2.0.0.241121-RCM
Show newest version
package nosi.core.xml;

import java.io.IOException;
import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;


import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
 * Emanuel
 * 4 Jun 2019
 */
public class DomXML {

	private final Document document;
	
	public DomXML(String xml) {
		this.document = this.extractXml(xml);
	}
	
	public Document extractXml(String xml) {
		try {
			DocumentBuilderFactory df = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = df.newDocumentBuilder();	
			InputSource src = new InputSource();
			src.setCharacterStream(new StringReader(xml.replace(" ", " ")));
			return builder.parse(src);
		} catch (ParserConfigurationException | SAXException | IOException e) {
			e.printStackTrace();
		} 
		return null;
	}
	
	public String getElement(String tagName) {
		if(this.document!=null) {
			NodeList element = this.document.getElementsByTagName(tagName);
			if(element.getLength() > 0)
				return element.item(0).getTextContent();
		}
		return null;
	}
	
	public Document getDocument() {
		return this.document;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy