I wrote a simple script that goes through xml file, takes random lines with specified tag (url) and strips everything that encapsulate link itself:
$importPath = "C:\PATH\feed.xml"
# get links
$link = Select-String '<loc>' $importPath
$count = 20
# randomize
$link = Get-Random -InputObject $link -Count $count
#strip
$link1 = $link -replace ".*<loc>" -replace "</loc>"
$rez = $link1 -join("`n")
Write-Host $rez -ForegroundColor Green
This works. However, I wonder if there is any way to improve this part, so I don't have to manually adjust it for each feed:
$link1 = $link -replace ".*<loc>" -replace "</loc>"
Since tag name can vary in name and length, I figured I could just use tag brackets (since that is a constant in every feed) to indicate where to start trimming.
$link1 = $link -replace ".*<" -replace "<.*"
Which obviously doesn't works since there is no distinction in which bracket should be considered the first one, and which should be considered the second one.
For example:
<tagnamethatvaries>https://somesite.com/somepath</tagnamethatvaries>
If I use
$link1 = $link -replace ".*<" -replace "<.*"
i get
/tagnamethatvaries>
Is there any way to declare point for the same character in string that varies in length?