如何避免字符串中的特殊字符

I'm parsing XML which contains URLs and I want to iterate over this XML to get all URLs and make a request to each URL, but the strings contain new line character . How can I avoid this new lines in URL?

Go version is go1.12.7 darwin/amd64. I have solution for this problem I just removing this characters from string.

package main

import (
    "encoding/xml"
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
    "strings"
)



type SitemapIndex struct {
    Locations []string `xml:"sitemap>loc"`
}

type NewsMap struct {
    Keyword  string
    Location string
}

type News struct {
    Titles    []string `xml:"url>news>title"`
    Keywords  []string `xml:"url>news>keywords"`
    Locations []string `xml:"url>loc"`
}


func main() {
    var s SitemapIndex
    var n News
    newsMap := make(map[string]NewsMap)
    resp, _ := http.Get("https://washingtonpost.com/news-sitemaps/index.xml")
    bytes, _ := ioutil.ReadAll(resp.Body)

    xml.Unmarshal(bytes, &s)

    for _, Location := range s.Locations {
        tempURL := strings.Replace(Location, "n", "", -1) // how to avoid new lines character in url?
        resp, err := http.Get(tempURL)
                // do some stuff...
}

Without this replace method on Location Im getting an error parse https://www.washingtonpost.com/news-sitemaps/politics.xml : net/url: invalid control character in URL exit status 1

Here is example XML file https://www.washingtonpost.com/news-sitemaps/politics.xml

The XML text contains newlines as mentioned by Dave C in a comment. Because newline is not allowed in URLs, you must remove the newlines.

Fix by replacing newline (instead of n) with "". Note the backslash.

tempURL := strings.Replace(Location, "
", "", -1) 

A better fix is to use strings.TrimSpace (also mentioned by Dave C). This will handle all extraneous whitespace that might be present in the file:

tempURL := strings.TrimSpace(Location)