Remove whitespace from XML input
976466
def _join_lines(txt):
    
    txt = txt or ''  # Handle NoneType input values
    val = ''
    lines = txt.split('\n')
    for line in lines:
        stripped = line.strip()
        if len(stripped) == 0:
            continue
        val += stripped + ' '
    return val.strip()
521669
function replaceXMLValuePair(input){
	//console.log('replace - repTotal: '+repTotal+' repPass: '+repCount+ ' repFailCount: '+repFailCount)
	//repTotal++
	if(input.indexOf('=')==-1)
		return false
	var self=this
	var prob=input.match(replaceXMLValuePairRegExp)
	if(prob != null){
		prob=prob.length
		var result=input.replace(replaceXMLValuePairRegExp,function(match){
			var valuePair=match.split(arguments[1])
			var pass=false
			var key=valuePair[0].trim()
			var value=valuePair[1].trim()
			if(key.length>0  && value.length>0){
				var newValue=self.storage.getValueForKey(key,'XMLValuePairStorage')
				self.storage.storeKeyValuePair([key,value],'XMLValuePairStorage')
				if(newValue!=value){
					pass=true;
					value=newValue;
				}
			}
			if(pass && !self.rint(prob)){
				//repCount++;
				prob++;
				/*console.log('Mutate')
				console.log('Replacing: '+match)
				console.log('With: '+valuePair[0]+arguments[1]+value)
				*/return valuePair[0]+arguments[1]+value
			}
			else{
				//repFailCount++;
				return match
			}
		})
		return result
	}
	return false
}
1076908
def pretty_xml(string_input, add_ns=False):
    
    if add_ns:
        elem = "<foo "
        for key, value in DOC_CONTENT_ATTRIB.items():
            elem += ' %s="%s"' % (key, value)
        string_input = elem + ">" + string_input + "</foo>"
    doc = minidom.parseString(string_input)
    if add_ns:
        s1 = doc.childNodes[0].childNodes[0].toprettyxml("  ")
    else:
        s1 = doc.toprettyxml("  ")
    return s1
695415
function strip_whitespace (s) {
      if (options.strip_whitespace) {
        return s.replace(/\s*\n/g,"\n").replace(/(\r?\n){2,}/g,"\n\n");
      }
      return s;
    }
885702
private String stripSuffix(final String input, final String searchString) {
        final String stripped = input.replace(searchString, "");
        return stripped.trim();
    }
1264980
public static String convertCharsFromXml(String input) {
		StringBuffer result = new StringBuffer();
		for(int i=0; i<input.length();) {
			if(input.charAt(i)=='&') {
				if(input.substring(i, i+3).equals("&lt;")) {
					result.append('<');
					i += 4;
				} else if(input.substring(i, i+3).equals("&gt;")) {
					result.append('>');
					i += 4;
				} else if(input.substring(i, i+4).equals("&amp;")) {
					result.append('&');
					i += 5;
				} else if(input.substring(i, i+5).equals("&quot;")) {
					result.append('"');
					i += 6;
				} else if(input.substring(i, i+5).equals("&apos;")) {
					result.append('\'');
					i += 6;
				} else {
					result.append(input.charAt(i));
					i++;
				}
			} else {
				result.append(input.charAt(i));
				i++;
			}
		}
		return result.toString();
	}
43924
function trimTrailingWhitespace(index, nextTag) {
    for (var endTag = null; index >= 0 && _canTrimWhitespace(endTag); index--) {
      var str = buffer[index];
      var match = str.match(/^<\/([\w:-]+)>$/);
      if (match) {
        endTag = match[1];
      }
      else if (/>$/.test(str) || (buffer[index] = collapseWhitespaceSmart(str, null, nextTag, options))) {
        break;
      }
    }
  }
208192
public function removeWhitespaces()
    {
        $txt = $this->filteredHtml;

        // exclude pre or code tags
        preg_match_all('!(<(?:code|pre|textarea).*>[^<]+</(?:code|pre|textarea)>)!umi', $txt, $pre);
        
        // removing all pre or code tags
        $txt = preg_replace('!<(?:code|pre|textarea).*>[^<]+</(?:code|pre|textarea)>!umi', '#pre#', $txt);

        $txt = preg_replace("/(?<=>)\s+|\s+(?=<)/umi", '', $txt);

        if(!empty($pre[0]))
        {
            foreach($pre[0] as $tag)
            {
                // putting back pre|code tags
                $txt = preg_replace('!#pre#!', trim($tag), $txt, 1);
            }
        }

        $this->filteredHtml = $txt;

        return $this;
    }
62157
private static String stripHtml(Content body) {
        String rawString = body.toString();
        // remove HTML tags
        rawString = rawString.replaceAll("\\<.*?>", " ");
        // consolidate multiple spaces between a word to a single space
        rawString = rawString.replaceAll("\\b\\s{2,}\\b", " ");
        // remove extra whitespaces
        return rawString.trim();
    }
517180
def collapse_whitespace(text):
    
    if text is None:
        return None
    if hasattr(text, 'xpath'):
        text = text.xpath('string()')
    text = re.sub('\s+', ' ', text)
    return text.strip()
1084025
def remove_xml_element_string(name, content):
    
    ET.register_namespace("", "http://soap.sforce.com/2006/04/metadata")
    tree = ET.fromstring(content)
    tree = remove_xml_element(name, tree)
    clean_content = ET.tostring(tree, encoding=UTF8)
    return clean_content
700941
function interElementWhiteSpace(node) {
  var value

  if (node && typeof node === 'object' && node.type === 'text') {
    value = node.value || ''
  } else if (typeof node === 'string') {
    value = node
  } else {
    return false
  }

  return value.replace(re, '') === ''
}
1362934
def remove_whitespace(text_string):
    '''
    
    '''
    if text_string is None or text_string == "":
        return ""
    elif isinstance(text_string, str):
        return " ".join(text_string.split())
    else:
        raise InputError("none type or string not passed as an argument")
181712
public static String convertCharsToXml(String input) {
		StringBuffer result = new StringBuffer();
		for(int i=0; i<input.length(); i++) {
			switch(input.charAt(i)) {
				case '<':	result.append("&lt;"); break;
				case '>':	result.append("&gt;"); break;
				case '"':	result.append("&quot;"); break;
				case '\'':	result.append("&apos;"); break;
				case '&':	result.append("&amp;"); break;
				default:	result.append(input.charAt(i));
			}
		}
		return result.toString().trim();
	}
1351356
def unnest(c, elem, ignore_whitespace=False):
        """"""
        parent = elem.getparent()
        gparent = parent.getparent()
        index = parent.index(elem)
        # put everything up to elem into a new parent element right before the current parent
        preparent = etree.Element(parent.tag)
        preparent.text, parent.text = (parent.text or ''), ''
        for k in parent.attrib.keys():
            preparent.set(k, parent.get(k))
        if index > 0:
            for ch in parent.getchildren()[:index]:
                preparent.append(ch)
        gparent.insert(gparent.index(parent), preparent)
        XML.remove_if_empty(preparent, leave_tail=True, ignore_whitespace=ignore_whitespace)
        # put the element right before the current parent
        XML.remove(elem, leave_tail=True)
        gparent.insert(gparent.index(parent), elem)
        elem.tail = ''
        # if the original parent is empty, remove it
        XML.remove_if_empty(parent, leave_tail=True, ignore_whitespace=ignore_whitespace)
302382
function cleanXML(xmlStr) {
    
    xmlStr = xmlStr.replace( /<!--[\s\S]*?-->/g, '' ); //remove commented lines
    xmlStr = xmlStr.replace(/\n|\t|\r/g, ''); //replace special characters
    xmlStr = xmlStr.replace(/ {1,}<|\t{1,}</g, '<'); //replace leading spaces and tabs
    xmlStr = xmlStr.replace(/> {1,}|>\t{1,}/g, '>'); //replace trailing spaces and tabs
    xmlStr = xmlStr.replace(/<\?[^>]*\?>/g, ''); //delete docType tags

    xmlStr = replaceSelfClosingTags(xmlStr); //replace self closing tags
    xmlStr = replaceAloneValues(xmlStr); //replace the alone tags values
    xmlStr = replaceAttributes(xmlStr); //replace attributes

    return xmlStr;
}
1140902
def _skip_whitespace(self):
        """"""
        i = 0
        while self._cur_token['type'] is TT.ws and not self._finished:
            self._increment()
            i += 1

        return i