<commit_before>package dk.in2isoft.commons.xml;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

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

import nu.xom.Attribute;
import nu.xom.Builder;
import nu.xom.Element;
import nu.xom.Node;
import nu.xom.ParentNode;
import nu.xom.ParsingException;
import nu.xom.ValidityException;
import nu.xom.XMLException;
import nu.xom.converters.DOMConverter;

import org.apache.tools.ant.filters.StringInputStream;
import org.ccil.cowan.tagsoup.Parser;
import org.eclipse.jdt.annotation.Nullable;
import org.jdom2.input.DOMBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import dk.in2isoft.commons.lang.Strings;

public class DOM {
	
	private static final Logger log = LoggerFactory.getLogger(DOM.class);

	public static List<Element> getAncestors(Node node) {
		List<Element> ancestors = new ArrayList<Element>();
		while (node.getParent() != null) {
			ParentNode parent = node.getParent();
			if (parent instanceof Element) {
				ancestors.add((Element) parent);
			}
			node = node.getParent();
		}
		return ancestors;
	}

	public static nu.xom.Document toXOM(Document domDocument) {
		try {
			return DOMConverter.convert(domDocument);
		} catch (XMLException e) {
			return null;<commit_msg>Better logging<commit_after>package dk.in2isoft.commons.xml;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

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

import nu.xom.Attribute;
import nu.xom.Builder;
import nu.xom.Element;
import nu.xom.Node;
import nu.xom.ParentNode;
import nu.xom.ParsingException;
import nu.xom.ValidityException;
import nu.xom.XMLException;
import nu.xom.converters.DOMConverter;

import org.apache.tools.ant.filters.StringInputStream;
import org.ccil.cowan.tagsoup.Parser;
import org.eclipse.jdt.annotation.Nullable;
import org.jdom2.input.DOMBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import dk.in2isoft.commons.lang.Strings;

public class DOM {
	
	private static final Logger log = LoggerFactory.getLogger(DOM.class);

	public static List<Element> getAncestors(Node node) {
		List<Element> ancestors = new ArrayList<Element>();
		while (node.getParent() != null) {
			ParentNode parent = node.getParent();
			if (parent instanceof Element) {
				ancestors.add((Element) parent);
			}
			node = node.getParent();
		}
		return ancestors;
	}

	public static nu.xom.Document toXOM(Document domDocument) {
		try {
			return DOMConverter.convert(domDocument);
		} catch (XMLException e) {
			log.warn("Unable to convert DOM to XOM", e);
			return null;
{'fraction_non_alphanumeric': 0.11227495908346972, 'fraction_numerical': 0.003927986906710311, 'mean_word_length': 5.075546719681909, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1207534', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1004, 'n_words': 209}