1

Official MS Documentation for XmlAttribute

Value is documented. But not #text, despite it working just fine.

See these posts using it:

access #text property of XMLAttribute in powershell

PowerShell edit #text from XML attributes

And this guide:

https://www.red-gate.com/simple-talk/sysadmin/powershell/powershell-data-basics-xml/

This code works:

[SelectXmlInfo]$out = Select-Xml '//*[local-name()="svg"]/@viewBox' -Path $TheSVGFile
$out | ForEach-Object {
    $_.Node.GetType()
    $_.Node.'#text'
}

Output:

enter image description here

Where is the documentation located for this mysterious property/attribute?

fmotion1
  • 237
  • 4
  • 12
  • 1
    `#text` as property name is a powershell thing stringifying xml nodes as property names thats why is not documented. see here https://learn.microsoft.com/en-us/dotnet/api/system.xml.xmlnode.name?view=net-7.0#property-value – Santiago Squarzon Jul 12 '23 at 04:23

1 Answers1

3

#text as Property Name is a PowerShell thing using the .ToString() representation of an Xml Node as property name that's why you don't see documented as a property in the XmlNode Class or any of its descendants.

Relevant documentation in this case is XmlNode.Name Property and XmlNodeType Enum.

$xml = [xml]::new()
$node = $xml.CreateTextNode('foo')
[pscustomobject]@{
    $node.ToString() = $node.Value
}

# #text
# -----
# foo
Santiago Squarzon
  • 41,465
  • 5
  • 14
  • 37