0

I'm trying to output "John Doe" to a string with OuterXml. The final line returns nothing.

<?xml version="1.0" encoding="utf-8"?>
<?mso-infoPathSolution name="urn:schemas-microsoft-com:office:infopath:New-Hire-Checklists:-myXSD-2016-01-21T15-44-37" solutionVersion="1.1.6.702" productVersion="16.0.0.0" PIVersion="1.0.0.0" href="https://symbiota.sharepoint.com/employeechecklists/NewHires/Forms/template.xsn"?>
<?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.4"?>
<?mso-infoPath-file-attachment-present?>
<my:myFields my:Empl-StartDate="2019-01-01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2016-01-21T15:44:37" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-US">
    <my:Empl-Name>John Doe</my:Empl-Name>
</my:myFields>
[xml]$user = Get-Content "C:\Powershell\jd.xml"

$user.myFields | Select-Object Empl-Name

# Output:
#
# Empl-Name      
# ---------      
# John Doe

$name = $user.myFields.OuterXml | Select-Object Empl-Name
$name

# Output:
#
# Empl-Name
# ---------
5
  • 1
    Select-Object Empl-Name -> Select-Object -ExpandProperty Empl-Name ? Commented May 14, 2018 at 17:40
  • that's it, thanks! Commented May 14, 2018 at 17:48
  • 2
    Any reason not to use $user.myFields."Empl-Name"? Commented May 14, 2018 at 18:36
  • Dot-access requires PowerShell v3 or newer if $user.myFields is an array. Select-Object -Expand works on all PowerShell versions. Commented May 14, 2018 at 19:01
  • 1
    @AnsgarWiechers also called member enumeration Commented May 14, 2018 at 19:11

1 Answer 1

1

trying to output "John Doe" to a string

Do this...

[xml]$doc = @"
<?xml version="1.0" encoding="utf-8"?>
<?mso-infoPathSolution name="urn:schemas-microsoft-com:office:infopath:New-Hire-Checklists:-myXSD-2016-01-21T15-44-37" solutionVersion="1.1.6.702" productVersion="16.0.0.0" PIVersion="1.0.0.0" href="https://symbiota.sharepoint.com/employeechecklists/NewHires/Forms/template.xsn"?>
<?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.4"?>
<?mso-infoPath-file-attachment-present?>
<my:myFields my:Empl-StartDate="2019-01-01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2016-01-21T15:44:37" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-US">
<my:Empl-Name>John Doe</my:Empl-Name>
</my:myFields>
"@

$doc.myFields."Empl-Name"

That last line will return a string. This is the easiest way.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.