<commit_before>package org.anyline.util;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class DomUtil {
    /**
     * 根据标签name搜索element
     * @param root 根节点
     * @param tag 标签名(不含namespace)
     * @return Element
     */
    public static Element element(Element root,String tag){
        Element result = null;
        Iterator<Element> it = root.elementIterator();
        while(it.hasNext() && null == result){
            Element e= it.next();
            if (e.getName().equals(tag)){
                result = e;
                break;
            }else{
                result = element(e, tag);
            }
        }
        return result;
    }
    /**
     * 根据标签name搜索element
     * @param root 根节点
     * @param tag 标签名(不含namespace)<commit_msg>DomUtil<commit_after>package org.anyline.util;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class DomUtil {

    /**
     * 根据标签name搜索element
     * @param root 根节点
     * @param tag 标签名(不含namespace)
     * @return Element
     */
    public static Element element(Element root,String tag){
        Element result = null;
        Iterator<Element> it = root.elementIterator();
        while(it.hasNext() && null == result){
            Element e= it.next();
            if (e.getName().equals(tag)){
                result = e;
                break;
            }else{
                result = element(e, tag);
            }
        }
        return result;
    }
    /**
     * 根据标签name搜索element
     * @param root 根节点
     * @param tag 标签名(不含namespace)
{'fraction_non_alphanumeric': 0.11303916707982152, 'fraction_numerical': 0.00495785820525533, 'mean_word_length': 2.182965299684543, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2399995', 'n_tokens_mistral': 649, 'n_tokens_neox': 674, 'n_words': 139}