locked
Help to edit an xml file RRS feed

  • Question

  • Good afternoon, I'm struggling trying to create a script that reads my rss feed and changes the title of the film in the example "3 Vaqueiros na Arábia (Outlaws of the Desert)", I would like to change it only to "Outlaws of the Desert"

    Feed:

    <rss version="2.0">
    <channel>
    <generator>ASC RSS 2.0</generator>
    <language>en</language>
    <link>https://myfeed.com</link>
    <copyright>Copyright My Feed</copyright>
    <pubDate>Tue, 21 Apr 2020 18:58:23 -0300</pubDate>
    <item>
    <title> 3 Vaqueiros na Arábia (Outlaws of the Desert)</title>
    <guid>https://myfeed.com/info.php?id=47123</guid>
    <link>https://myfeed.com/info.php?id=47123</link>
    <pubDate>2020-04-21 21:39:32</pubDate>
    <category> Movies: </category>
    <description>
    Category: Movies 2020-04-21 21:39:32
    </description>

    </item>

    Tuesday, April 21, 2020 10:05 PM

All replies

  • You cannot change an RSS feed.  You would have to change the database that it is sourced from.  RSS is a service and the output is just a report.

    Why would you want to change an RSS feed? Are you trying to hack some site?


    \_(ツ)_/

    Tuesday, April 21, 2020 10:11 PM
  • Given that your XML is a broken fragment here is how to modify the XML if that is what you are trying to do.

    [xml]$xml = @'
    <rss version="2.0">
        <channel>
            <generator>ASC RSS 2.0</generator>
            <language>en</language>
            <link>https://myfeed.com</link>
            <copyright>Copyright My Feed</copyright>
            <pubDate>Tue, 21 Apr 2020 18:58:23 -0300</pubDate>
            <item>
                <title> 3 Vaqueiros na Arábia (Outlaws of the Desert)</title>
                <guid>https://myfeed.com/info.php?id=47123</guid>
                <link>https://myfeed.com/info.php?id=47123</link>
                <pubDate>2020-04-21 21:39:32</pubDate>
                <category> Movies: </category>
                <description>
                Category: Movies 2020-04-21 21:39:32
                </description>
            </item>
        </channel>
    </rss>
    '@
    $xml.rss.channel.item.title
    # returns title
    $xml.rss.channel.item.title = 'my new title'
    $xml.rss.channel.item.title



    \_(ツ)_/

    Tuesday, April 21, 2020 10:16 PM
  • No, it is only for a reader, this is the result that leaves the site I want you not to get the title of the film in two languages only in English.
    Wednesday, April 22, 2020 1:05 AM
  • Given that your XML is a broken fragment here is how to modify the XML if that is what you are trying to do.

    [xml]$xml = @'
    <rss version="2.0">
        <channel>
            <generator>ASC RSS 2.0</generator>
            <language>en</language>
            <link>https://myfeed.com</link>
            <copyright>Copyright My Feed</copyright>
            <pubDate>Tue, 21 Apr 2020 18:58:23 -0300</pubDate>
            <item>
                <title> 3 Vaqueiros na Arábia (Outlaws of the Desert)</title>
                <guid>https://myfeed.com/info.php?id=47123</guid>
                <link>https://myfeed.com/info.php?id=47123</link>
                <pubDate>2020-04-21 21:39:32</pubDate>
                <category> Movies: </category>
                <description>
                Category: Movies 2020-04-21 21:39:32
                </description>
            </item>
        </channel>
    </rss>
    '@
    $xml.rss.channel.item.title
    # returns title
    $xml.rss.channel.item.title = 'my new title'
    $xml.rss.channel.item.title



    \_(ツ)_/

    As I tried to explain, this script downloads the feed from a website with a list of films currently playing. However in the "title" it comes in two languages. I just want to keep the title in parentheses, remove the text that is in Portuguese
    Wednesday, April 22, 2020 1:12 AM
  • Yes.  You will have to write a script to do that.  Have you tried?  We don't write custom script on request.  The forum is for answering questions about scripting and not for providing free script writing.

    I showed you haw to find and change the item in an XML file.  It is up to you to write your script.


    \_(ツ)_/

    Wednesday, April 22, 2020 1:18 AM
  • Yes.  You will have to write a script to do that.  Have you tried?  We don't write custom script on request.  The forum is for answering questions about scripting and not for providing free script writing.

    I showed you haw to find and change the item in an XML file.  It is up to you to write your script.


    \_(ツ)_/

    $file = "C:\RSS\NewRSS.xml"
    $xml = [xml](Get-Content "C:\RSS\NewRSS.xml")
    
    $Movie = $xml.rss.channel.item.title
    
    $titleFilm = ($Movie | Select-String ".?\((.*?)\).*" -AllMatches).Matches.Value |
        ForEach-Object {
            $_.trimStart().trimEnd()
        }
    $titleFilm = $titleFilm -replace "[)(]",""
    
    write-host "$titleFilm"
    That was the little I got, but it returns all names on a single line, I couldn't find a way to return each separate result to create the changed file. The little I did was reading other models on the forum but I am still very limited and I thank you for your attention.


    Wednesday, April 22, 2020 1:23 AM
  • Thimk!

    [xml]$xml= Get-Content C:\RSS\NewRSS.xml
    $xml.rss.channel.item.title |
        ForEach-Object{
            $_ -match '\((.*)\)'
            $matches[1]
    }


    \_(ツ)_/

    Wednesday, April 22, 2020 2:37 AM
  • Thimk!

    [xml]$xml= Get-Content C:\RSS\NewRSS.xml
    $xml.rss.channel.item.title |
        ForEach-Object{
            $_ -match '\((.*)\)'
            $matches[1]
    }


    \_(ツ)_/

    Resolved:

    [xml]$xml= Get-Content C:\RSS\RSS.xml
    foreach ($item in $xml.rss.channel.item) {
        if ($item.title -match '\((.*)\)') {
            $item.title = $matches[1]
        }
    }
    $xml.Save('C:\RSS\RSS.xml')

    Wednesday, April 22, 2020 4:47 PM