# xml without name attribute

**URL:** <https://forums.powershell.org/t/xml-without-name-attribute/15061>\
**Category:** PowerShell Help\
**Created:** [October 7, 2020, 12:28pm UTC](https://forums.powershell.org/t/xml-without-name-attribute/15061 "2020-10-07T12:28:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![john-curtiss](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@john-curtiss](https://forums.powershell.org/u/john-curtiss)\
**Post date:** [October 7, 2020, 12:28pm UTC](https://forums.powershell.org/t/xml-without-name-attribute/15061/1 "2020-10-07T12:28:57Z")

</div>

&nbsp;

i have a file where everything under “edgepolicies” is a unique name, but

$xml.root.edgePolicies.ChildNodes

returns the structure underneath the child nodes, without the names of the actual child nodes.

i’d like an array with a name, level, source, and value column.

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![john-curtiss](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@john-curtiss](https://forums.powershell.org/u/john-curtiss)\
**Post date:** [October 7, 2020, 12:33pm UTC](https://forums.powershell.org/t/xml-without-name-attribute/15061/2 "2020-10-07T12:33:59Z")

</div>

```
<?xml version="1.0" encoding="UTF-8" ?>
<root>
  <edgeMetadata>
    <OS>Windows 10 OS Version 1909 (Build 18363.997)</OS>
    <application>Microsoft Edge</application>
    <revision>54dee5e1d729e4c188896f1b1156e98e83557fcc</revision>
    <version>85.0.564.63 (Official build) (64-bit)</version>
  </edgeMetadata>
  <edgePolicies>
    <AllowDeletingBrowserHistory>
      <level>mandatory</level>
      <scope>user</scope>
      <source>platform</source>
      <value>false</value>
    </AllowDeletingBrowserHistory>
    <AudioCaptureAllowedUrls>
      <level>mandatory</level>
      <scope>user</scope>
      <source>platform</source>
      <value>[*.]fake.com</value>
    </AudioCaptureAllowedUrls>
    <AuthNegotiateDelegateAllowlist>
      <level>mandatory</level>
      <scope>user</scope>
      <source>platform</source>
 </edgePolicies>
</root>
```

&nbsp;

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [October 7, 2020, 1:02pm UTC](https://forums.powershell.org/t/xml-without-name-attribute/15061/3 "2020-10-07T13:02:03Z")

</div>

You can use the hidden get\_name() method.

```
$xml.root.edgePolicies.ChildNodes | Select-Object @{n="Name";e={$_.get_name()}},level,source,value
```

or

```
$xml.Selectnodes("//edgePolicies").childnodes | Select-Object @{n="Name";e={$_.get_name()}},level,source,value
```

Output

```
Name level source value       
---- ----- ------ -----       
AllowDeletingBrowserHistory mandatory platform false       
AudioCaptureAllowedUrls mandatory platform [*.]fake.com
AuthNegotiateDelegateAllowlist mandatory platform
```

You can view the hidden methods/properties by using Get-Member -Force

```
$xml | Get-Member -Force
```

---

<div class="post-metadata">

**Author:** ![john-curtiss](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@john-curtiss](https://forums.powershell.org/u/john-curtiss)\
**Post date:** [October 8, 2020, 5:53am UTC](https://forums.powershell.org/t/xml-without-name-attribute/15061/4 "2020-10-08T05:53:17Z")

</div>

well thank heavens they hid it. 🙂

~~bonus round: what if some objects have more properties than just “level, source, value”, and i don’t necessarily know what those properties are ahead of time?~~

nevermind on that one. $xml.root.edgePolicies.ChildNodes seems to show me everything.

also: just for grins, is there a json version of get\_name? my initial file was json, and about two frustrating hours after reading my first “but convertfrom-json is so easy!!” article, i figured ‘i’m at least familiar with working with xml, can i convert json to xml and go from there?..yes.’

---

<div class="post-metadata">

**Author:** ![john-curtiss](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@john-curtiss](https://forums.powershell.org/u/john-curtiss)\
**Post date:** [October 8, 2020, 6:24am UTC](https://forums.powershell.org/t/xml-without-name-attribute/15061/5 "2020-10-08T06:24:25Z")

</div>

```
{
   "edgeMetadata": {
      "OS": "Windows 10 OS Version 1909 (Build 18363.997)",
      "application": "Microsoft Edge",
      "revision": "54dee5e1d729e4c188896f1b1156e98e83557fcc",
      "version": "85.0.564.63 (Official build) (64-bit)"
   },
   "edgePolicies": {
      "AllowDeletingBrowserHistory": {
         "level": "mandatory",
         "scope": "user",
         "source": "platform",
         "value": "false"
      },
      "AudioCaptureAllowedUrls": {
         "level": "mandatory",
         "scope": "user",
         "source": "platform",
         "value": "[*.]fake.com"
      },
      "AuthNegotiateDelegateAllowlist": {
         "level": "mandatory",
         "scope": "user",
         "source": "platform"
      }
   }
}
```

here is a json sample. again i can get to $json.edgepolicies, but i don’t see any promising methods or properties in get-member -force here. all of my ‘nodes’ are listed as noteproperties.

&nbsp;

AllowDeletingBrowserHistory NoteProperty System.Management.Automation.PSCustomObject AllowDeletingBrowserHistory=@{level=mandatory; scope=user; source=platform; value=False}  
AudioCaptureAllowedUrls NoteProperty System.Management.Automation.PSCustomObject AudioCaptureAllowedUrls=@{level=mandatory; scope=user; source=platform; value=System.Object}

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [October 9, 2020, 11:50am UTC](https://forums.powershell.org/t/xml-without-name-attribute/15061/6 "2020-10-09T11:50:02Z")

</div>

```
$json = @"
{
   "edgeMetadata": {
      "OS": "Windows 10 OS Version 1909 (Build 18363.997)",
      "application": "Microsoft Edge",
      "revision": "54dee5e1d729e4c188896f1b1156e98e83557fcc",
      "version": "85.0.564.63 (Official build) (64-bit)"
   },
   "edgePolicies": {
      "AllowDeletingBrowserHistory": {
         "level": "mandatory",
         "scope": "user",
         "source": "platform",
         "value": "false"
      },
      "AudioCaptureAllowedUrls": {
         "level": "mandatory",
         "scope": "user",
         "source": "platform",
         "value": "[*.]fake.com"
      },
      "AuthNegotiateDelegateAllowlist": {
         "level": "mandatory",
         "scope": "user",
         "source": "platform"
      }
   }
}
"@ | ConvertFrom-Json

$json.edgePolicies.PSObject.Properties | foreach {
    [pscustomobject]@{
        Name = $_.Name
        Level = $_.Value.Level
        Scope = $_.Value.Scope
        Source = $_.Value.Source
        Value = $_.Value.value
    }
}
```

---

<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, 8:28pm UTC](https://forums.powershell.org/t/xml-without-name-attribute/15061/7 "2024-05-16T20:28:45Z")

</div>

Closed on May 16, 2024, 8:28pm UTC


