# Invoke-Rest method and XML CDATA?

**URL:** <https://forums.powershell.org/t/invoke-rest-method-and-xml-cdata/1195>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/invoke-rest-method-and-xml-cdata/1195 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/invoke-rest-method-and-xml-cdata/1195/1 "2011-12-31T18:30:00Z")

</div>

by yooakim at 2012-08-15 01:20:27

> I am Learning PowerShell and love it more by every day. It’s simple and elegant! And I love the object pipeline, it makes stitching things togehter childs play (almost!)  
>   
> I have a question about using the Invoke-Rest method. I use it against a RSS feed. This particular RSS feed wraps the contents of title, description and other elements in `<title><![CDATA[HÃ¤r Ã¤r texten med lite specialare]]</title>`  
>   
> When I use this code  
>   
> `Invoke-RestMethod $url`  
>   
> Everything works but the result does not give me the content of the CDATA elements. I know I can use .innerText on these elements but am wondering if there is Another, easier, way to do this?  
>   
> Any suggestions of how to obtain content of CDATA elements?  
>   
> Cheers,  
> Joakim

by DougFinke at 2012-08-15 12:14:02

> Hi Joakim and thanks for the post.  
>   
> You should be able to get the content of the CDATA section this way.  
>   
> `(Invoke-RestMethod $url).Title.InnerText `  
>   
> Here’s the challenge, if the Title does not contain a CDATA section, this will print nothing.  
>   
> So, you’ll need to foreach over the results and check and either print the Title or Title.InnerText.  
>   
> Post the RSS feed url and we can take a look.  
>   
> Thanks  
> Doug

by yooakim at 2012-08-15 22:24:58

> Thanks, this is the URL I’m reading from:  
>   
> http://sverigesradio.se/api/rss/pod/4023  
>   
> I’m not sure why the keep encoding everything in CDATA since it is UTF-8 but they do… 😉  
>   
> /j

by DougFinke at 2012-08-16 04:31:26

> Yes, many sites do things differently with their feeds. The good news is, PowerShell is flexible enough so you don’t hit too many walls. Below are a couple ways you could process that feed. From a quick look, it seems they are all wrapped in CDATA sections.  
>   
>   
> `Invoke-RestMethod http://sverigesradio.se/api/rss/pod/4023 | Select Pubdate, Author, @{Name=‘Title’; Expression={$.Title.InnerText}}`  
>   
>   
> _`Invoke-RestMethod http://sverigesradio.se/api/rss/pod/4023 | ForEach { [PSCustomObject] @{ Pubdate = $`_`.pubdate Title = $.Title.InnerText Author = $.Author }}`

by yooakim at 2012-08-16 04:59:32

> With PowerShell v3.0 it’s so elegant! Thanks 🙂  
>   
> /joakim

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:04pm UTC](https://forums.powershell.org/t/invoke-rest-method-and-xml-cdata/1195/2 "2024-05-16T21:04:31Z")

</div>


