title: How do I stop getting an object from two similar named XML nodes when am creating a custom object
body: <p>I am trying to parse several RSS news feeds which I will later filter based on what I am looking for.  Each feed has a slightly different XML Schema but in general has a Title, Description, link and pubDate.  Some use a CDATA section, and some don't, so I incorporated and if statement for those that use it.  I am trying to write one routine that matches all.  Here is a sample of the XML giving me the headache:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;rss xmlns:media=&quot;http://search.yahoo.com/mrss/&quot; xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot; version=&quot;2.0&quot;&gt;
    &lt;channel&gt;
      &lt;title&gt;&lt;![CDATA[ABC7 RSS Feed]]&gt;&lt;/title&gt;
      &lt;link&gt;&lt;![CDATA[https://abc7news.com/feed]]&gt;&lt;/link&gt;
      &lt;lastBuildDate&gt;&lt;![CDATA[Thu, 13 Jan 2022 15:49:04 +0000]]&gt;&lt;/lastBuildDate&gt;
      &lt;pubDate&gt;&lt;![CDATA[Thu, 13 Jan 2022 15:49:04 +0000]]&gt;&lt;/pubDate&gt;
      &lt;description&gt;Keep up with news from your local ABC station.&lt;/description&gt;
      &lt;copyright&gt;Copyright 2022 ABC Inc., KGO-TV San Francisco&lt;/copyright&gt;
      &lt;managingEditor&gt;KGO-TVWebTeam@email.disney.com(KGO-TV San Francisco)&lt;/managingEditor&gt;
      &lt;webMaster&gt;KGO-TVWebTeam@email.disney.com(KGO-TV San Francisco)&lt;/webMaster&gt;
      &lt;language&gt;&lt;![CDATA[en]]&gt;&lt;/language&gt;
      &lt;item&gt;
        &lt;title&gt;&lt;![CDATA[Biden gives COVID response update; administration to deploy military teams to hospitals | LIVE]]&gt;&lt;/title&gt;
        &lt;description&gt;&lt;![CDATA[Starting next week, 1,000 military medical personnel will begin arriving to help mitigate staffing crunches at hospitals across the country. ]]&gt;&lt;/description&gt;
        &lt;pubDate&gt;&lt;![CDATA[Thu, 13 Jan 2022 15:38:02 +0000]]&gt;&lt;/pubDate&gt;
        &lt;link&gt;&lt;![CDATA[https://abc7news.com/us-covid-biden-speech-today-hospitalizations/11462828/]]&gt;&lt;/link&gt;
        &lt;type&gt;&lt;![CDATA[post]]&gt;&lt;/type&gt;
        &lt;guid&gt;&lt;![CDATA[https://abc7news.com/us-covid-biden-speech-today-hospitalizations/11462828/]]&gt;&lt;/guid&gt;
        &lt;dc:creator&gt;&lt;![CDATA[AP]]&gt;&lt;/dc:creator&gt;
        &lt;media:keywords&gt;&lt;![CDATA[us covid, biden covid, biden speech today, covid hospitalizations, omicron variant, us hospitals, covid cases, covid omicron, biden military medical teams]]&gt;&lt;/media:keywords&gt;
        &lt;category&gt;&lt;![CDATA[Health &amp; Fitness,omicron variant,Coronavirus,military,joe biden,hospitals,u.s. &amp; world]]&gt;&lt;/category&gt;
        &lt;guid isPermaLink=&quot;false&quot;&gt;health/live-biden-highlighting-federal-surge-to-help-weather-omicron/11462828/&lt;/guid&gt;
      &lt;/item&gt;
      &lt;item&gt;
        &lt;title&gt;&lt;![CDATA[Massive backup on Bay Bridge after early morning crash]]&gt;&lt;/title&gt;
        &lt;description&gt;&lt;![CDATA[A massive backup continues on the Bay Bridge after an earlier multi-vehicle crash past Treasure Island.]]&gt;&lt;/description&gt;
        &lt;pubDate&gt;&lt;![CDATA[Thu, 13 Jan 2022 15:30:15 +0000]]&gt;&lt;/pubDate&gt;
        &lt;link&gt;&lt;![CDATA[https://abc7news.com/bay-bridge-crash-traffic-accident-sf-commute/11463119/]]&gt;&lt;/link&gt;
        &lt;type&gt;&lt;![CDATA[post]]&gt;&lt;/type&gt;
        &lt;guid&gt;&lt;![CDATA[https://abc7news.com/bay-bridge-crash-traffic-accident-sf-commute/11463119/]]&gt;&lt;/guid&gt;
        &lt;dc:creator&gt;&lt;![CDATA[KGO]]&gt;&lt;/dc:creator&gt;
        &lt;media:title&gt;&lt;![CDATA[Crash triggers massive backup on Bay Bridge]]&gt;&lt;/media:title&gt;
        &lt;media:description&gt;&lt;![CDATA[A crash on the Bay Bridge triggered massive gridlock for the Thursday morning commute.]]&gt;&lt;/media:description&gt;
        &lt;media:videoId&gt;11463404&lt;/media:videoId&gt;
        &lt;media:thumbnail url=&quot;https://cdn.abcotvs.com/dip/images/11463261_011322-kgo-sky7-bay-bridge-traffic-img.jpg&quot; width=&quot;1280&quot; height=&quot;720&quot; /&gt;
        &lt;enclosure url=&quot;https://vcl.abcotv.net/video/kgo/011322-kgo-6am-bay-bridge-crash-vid.mp4&quot; length=&quot;79&quot; type=&quot;video/mp4&quot; /&gt;
        &lt;media:keywords&gt;&lt;![CDATA[Bay Bridge crash, traffic, accident, SF commute, Oakland drive times, bay bridge toll plaza backup, Bay Area, treasure island,]]&gt;&lt;/media:keywords&gt;
        &lt;category&gt;&lt;![CDATA[Traffic,Treasure Island,Oakland,San Francisco,CHP,bay bridge,crash]]&gt;&lt;/category&gt;
        &lt;guid isPermaLink=&quot;false&quot;&gt;traffic/massive-backup-on-bay-bridge-after-early-morning-crash/11463119/&lt;/guid&gt;
      &lt;/item&gt;
    &lt;/channel&gt;
  &lt;/rss&gt;
  </code></pre>
  <p>and Here is the parsing code which puts each item into a object ($posts):</p>
  <pre><code>    $rss = [xml] (Get-Content 'I:\RSS_Project\Feeds\feed-3.xml')
      $rss.SelectNodes('//item')|%{
      $posts += New-Object psobject -Property @{
          Title = If($_.Title.&quot;#cdata-section&quot;){$_.Title.&quot;#cdata-section&quot;}else{$_.Title}
          Desc = If($_.description.&quot;#cdata-section&quot;){$_.description.&quot;#cdata-section&quot;}else{$_.Title}
          link = If($_.link.&quot;#cdata-section&quot;){$_.link.&quot;#cdata-section&quot;}else{$_.link}
          pubDate = If($_.pubDate.&quot;#cdata-section&quot;){$_.pubDate.&quot;#cdata-section&quot;}else{$_.pubDate}
          
          }
      }
  </code></pre>
  <p>I get the right link and pubDate with this feed but because there is a media:title and media:description in some items,(yes not consistent in the same feed), and so I get {title,media:title} output into the $posts.title custom object I created.</p>
  <p>With this data it would be {Massive backup on Bay Bridge after early morning crash,Crash triggers massive backup on Bay Bridge}.  I can't figure out how to avoid capturing the  media:title data.  My other XML feeds don't have the media:title.</p>
  <p>Can I do I pre-emptive strike and remove this ahead of time if it exists in any feeds? I tried using $_.Title[0] which worked on this feed but as the other feeds don't have the array, it did not work on those. I have the same issue where media:description exists in the item.  I output the data into an HTML table which only lists &quot;System.Object&quot; when I have the title or description array.  Any help to eliminate the media:title into my object would be greatly appreciated.</p>