<commit_before>/**
@module bee
**/
var fs = require('fs');
var util = require('util');
var path = require('path');

var bee = require('./bee');
var task = require('./task');
var Target = require('./Target');
var Project = require('./Project');
var beeutil = require('./util');
/*
@class XMLParser
@internal
@static
*/

/*
解析xml配置文件，生成一个Project
@method parse
@param {String} file xml配置文件
@param {String} encoding 编码
@static
@return {Project} 
*/
exports.parse = function(file, encoding) {

  var jsxml = require('node-jsxml');
  var xml = new jsxml.XML(fs.readFileSync(file, encoding || 'utf-8'));

  //xml util
  var xu = {
    /*
    获取xml节点的文本
    */
    text: function(node) {
      return node.text().toString();
    },
    /*
    获取xml节点的属性
    */
    attr: function(node, name) {
      return node.attribute(name).toString();
    },
    /*
    先从文本获取值，如果没有，则从指定的属性获取值
    */
    textOrAttr: function(node, name) {
      return this.text(node) || this.attr(node, name);
    },
    /*
    先从某个子节点的文本获取值，如果没有，则从指定的属性获取值
    */
    childOrAttr: function(node, name) {
      return this.textOrAttr(node.child(name), name);
    },
    /*
    xml转换成json
    */
    xml2json: function(xml) {
      var obj = {
        childNodes: []
      };
      xml.attributes("*").each(function(attr) {
        obj[attr.localName()] = attr.toString();
      });
      if (xml.hasComplexContent()) {

        xml.children().each(function(child) {
          obj.childNodes.push({
            name: child.localName(),
            value: xu.xml2json(child)
          })
        });
      } else {
        if (!obj.value) {
          obj.value = this.text(xml);
        }
      }
      return obj;
    }<commit_msg>use description attribute<commit_after>/**
@module bee
**/
var fs = require('fs');
var util = require('util');
var path = require('path');

var bee = require('./bee');
var task = require('./task');
var Target = require('./Target');
var Project = require('./Project');
var beeutil = require('./util');
/*
@class XMLParser
@internal
@static
*/

/*
解析xml配置文件，生成一个Project
@method parse
@param {String} file xml配置文件
@param {String} encoding 编码
@static
@return {Project} 
*/
exports.parse = function(file, encoding) {

  var jsxml = require('node-jsxml');
  var xml = new jsxml.XML(fs.readFileSync(file, encoding || 'utf-8'));

  //xml util
  var xu = {
    /*
    获取xml节点的文本
    */
    text: function(node) {
      return node.text().toString();
    },
    /*
    获取xml节点的属性
    */
    attr: function(node, name) {
      return node.attribute(name).toString();
    },
    /*
    先从文本获取值，如果没有，则从指定的属性获取值
    */
    textOrAttr: function(node, name) {
      return this.text(node) || this.attr(node, name);
    },
    /*
    先从某个子节点的文本获取值，如果没有，则从指定的属性获取值
    */
    childOrAttr: function(node, name) {
      return this.text(node.child(name)) || this.attr(node, name);
    },
    /*
    xml转换成json
    */
    xml2json: function(xml) {
      var obj = {
        childNodes: []
      };
      xml.attributes("*").each(function(attr) {
        obj[attr.localName()] = attr.toString();
      });
      if (xml.hasComplexContent()) {

        xml.children().each(function(child) {
          obj.childNodes.push({
            name: child.localName(),
            value: xu.xml2json(child)
          })
        });
      } else {
        if (!obj.value) {
          obj.value = this.text(xml);
        }
      }
      return obj;
    }
{'fraction_non_alphanumeric': 0.17071742313323574, 'fraction_numerical': 0.0017569546120058566, 'mean_word_length': 2.32295719844358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 34}, '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': '4285724', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1244, 'n_words': 225}