title: PowerShell read on null XML returns System.Xml.XmlElement
body: <p>I am using PowerShell to read some XML documents created from SharePoint forms and some fields appear to allow nulls (xsi:nil="true") and when nothing is found it will return "System.Xml.XmlElement". Is there a way to avoid this response and get either an empty string or nothing back? </p>
  
  <pre><code>$xml = New-Object -TypeName XML
  $xml.Load($fullpath)
  $sf_r_l5_q1 = $xml.myFields.SF_R_L5_Q1
  Write-Host "variable is $sf_r_l5_q1"
  
  &lt;my:SF_R_L5_Q1 xsi:nil="true"/&gt;
  variable is System.Xml.XmlElement
  </code></pre>
  
  <p>After some testing I'm adding a fully functional code snippet to try and show the issue. In the new code below Q1 and Q3 are giving me a headache. IsEmpty does work on Q1 but not on Q3. Both Q1 and Q3 seem to be valid XML format and I think both are possible in the InfoPath forms so I need to try and be ready for each. I can use IsEmpty on the Q1 format but I still can't find a way to work with the Q3 format. </p>
  
  <pre><code>$doc = [xml]@'
  &lt;xml&gt;
      &lt;my:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2017-05-05T14:19:13" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls" xmlns:ma="http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes" xmlns:d="http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields" xmlns:q="http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:dms="http://schemas.microsoft.com/office/2009/documentManagement/types" xmlns:tns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService" xmlns:s1="http://microsoft.com/wsdl/types/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-US"&gt;
          &lt;my:Q1 xsi:nil="true" /&gt;
          &lt;my:Q2 /&gt;
          &lt;my:Q3 xsi:nil="true"&gt;&lt;/my:Q3&gt;
          &lt;my:Q4&gt;true&lt;/my:Q4&gt;
      &lt;/my:myFields&gt;
  &lt;/xml&gt;
  '@
  
  $q1 = $doc.xml.myFields.Q1
  $q2 = $doc.xml.myFields.Q2
  $q3 = $doc.xml.myFields.Q3
  $q4 = $doc.xml.myFields.Q4
  $q1value = $doc.xml.myFields.Q1.Value
  $q3value = $doc.xml.myFields.Q3.Value
  $q4value = $doc.xml.myFields.Q4.Value
  $q1_isempty = if ($doc.xml.myFields.Q1.IsEmpty) {"true"} else {"false"}
  $q3_isempty = if ($doc.xml.myFields.Q3.IsEmpty) {"true"} else {"false"}
  $q3value_blank = if ($doc.xml.myFields.Q3.Value -eq "") {"true"} else {"false"}
  $q3_blank = if ($doc.xml.myFields.Q3 -eq "") {"true"} else {"false"}
  Write-Host "Q1 $q1"
  Write-Host "Q2 $q2"
  Write-Host "Q3 $q3"
  Write-Host "Q4 $q4"
  Write-Host "Q1value $q1value"
  Write-Host "Q3value $q3value"
  Write-Host "Q4value $q4value"
  Write-Host "Q1 IsEmpty $q1_isempty"
  Write-Host "Q3 IsEmpty $q3_isempty"
  Write-Host "Q3value blank $q3value_blank"
  Write-Host "Q3 blank $q3_blank"
  
  
  
  Q1 System.Xml.XmlElement
  Q2 
  Q3 System.Xml.XmlElement
  Q4 true
  Q1value 
  Q3value 
  Q4value 
  Q1 IsEmpty true
  Q3 IsEmpty false
  Q3value blank false
  Q3 blank false
  </code></pre>