# Powershell XPATH seems to be not working

**URL:** <https://forums.powershell.org/t/powershell-xpath-seems-to-be-not-working/21920>\
**Category:** PowerShell Help\
**Created:** [March 21, 2023, 7:27am UTC](https://forums.powershell.org/t/powershell-xpath-seems-to-be-not-working/21920 "2023-03-21T07:27:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![edvrfn](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@edvrfn](https://forums.powershell.org/u/edvrfn)\
**Post date:** [March 21, 2023, 7:27am UTC](https://forums.powershell.org/t/powershell-xpath-seems-to-be-not-working/21920/1 "2023-03-21T07:27:05Z")

</div>

I am using Wifi profile xml files as an example.

In the below code if i use xpath as `$XPath = "//*"` I get the list of all nodes in the xml.

But if I specify specific node and all nodes under it with `$XPath = "//WLANProfile//*"`, I get nothing.

Is there something wrong I am doing or does Powershell xpath work differently.

```auto
$path = "c:\something\wifi.xml"

$XPath = "//WLANProfile//*"

$xmlContent = [xml](Get-Content $path)

#This does not work unless $XPath is changed to "//*"
Select-Xml -Xml $xmlContent -XPath $XPath | Select-Object -ExpandProperty Node

#Just testing another way and same here only works when $XPath is equal to "//*"
$xmlContent.SelectNodes("//*")

```

XML

```auto
<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
	<name>Guest</name>
	<SSIDConfig>
		<SSID>
			<hex>436170552D477485693</hex>
			<name>dd</name>
		</SSID>
	</SSIDConfig>
	<connectionType>ESS</connectionType>
	<connectionMode>manual</connectionMode>
	<MSM>
		<security>
			<authEncryption>
				<authentication>WPA2PSK</authentication>
				<encryption>AES</encryption>
				<useOneX>false</useOneX>
			</authEncryption>
			<sharedKey>
				<keyType>passPhrase</keyType>
				<protected>true</protected>
				<keyMaterial>secretstring</keyMaterial>
			</sharedKey>
		</security>
	</MSM>
	<MacRandomization xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">
		<enableRandomization>false</enableRandomization>
	</MacRandomization>
</WLANProfile>

```

---

<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:** [March 21, 2023, 3:43pm UTC](https://forums.powershell.org/t/powershell-xpath-seems-to-be-not-working/21920/2 "2023-03-21T15:43:35Z")

</div>

Never really used xPath in the many times I’ve done XML parsing, I’ve always used dot notation:

```auto
[xml]$xml = Get-Content -Path C:\Scripts\wifi.xml
$xml.WLANProfile.connectionMode
$xml.WLANProfile.MSM.security.authEncryption.authentication

```

This XML looks straight forward, so is there a reason that you are attempting to leverage XPath?

---

<div class="post-metadata">

**Author:** ![edvrfn](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@edvrfn](https://forums.powershell.org/u/edvrfn)\
**Post date:** [March 21, 2023, 6:09pm UTC](https://forums.powershell.org/t/powershell-xpath-seems-to-be-not-working/21920/3 "2023-03-21T18:09:41Z")

</div>

@rob-simmers no special reason. I don’t work a lot with xml files and google pointed me to xpath. I was thinking this will result in spiting out all the nodes in xml and can be a template for any other similar xml file.

---

<div class="post-metadata">

**Author:** ![edvrfn](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@edvrfn](https://forums.powershell.org/u/edvrfn)\
**Post date:** [March 22, 2023, 2:29am UTC](https://forums.powershell.org/t/powershell-xpath-seems-to-be-not-working/21920/4 "2023-03-22T02:29:17Z")

</div>

I have come this close

This seems to be caused by namespace as removing the line ‘xmlns=“[http://www.microsoft.com/networking/WLAN/profile/v1](http://www.microsoft.com/networking/WLAN/profile/v1)”’ does make it work.

And I tried using the -Namespace as below and it doesn’t work

```auto
Select-Xml '//WLANProfile//*' -Namespace @{'xml'='http://www.microsoft.com/networking/WLAN/profile/v1'} -xml $xmlContent

```

when namespace is manually removed from file  
`Node Path Pattern`  
`---- ---- -------`  
`name InputStream //WLANProfile//*`  
`SSIDConfig InputStream //WLANProfile//*`  
`SSID InputStream //WLANProfile//*`  
`hex InputStream //WLANProfile//*`  
`name InputStream //WLANProfile//*`  
`connectionType InputStream //WLANProfile//*`  
`connectionMode InputStream //WLANProfile//*`  
`MSM InputStream //WLANProfile//*`  
`security InputStream //WLANProfile//*`  
`authEncryption InputStream //WLANProfile//*`  
`authentication InputStream //WLANProfile//*`  
`encryption InputStream //WLANProfile//*`  
`useOneX InputStream //WLANProfile//*`  
`sharedKey InputStream //WLANProfile//*`  
`keyType InputStream //WLANProfile//*`  
`protected InputStream //WLANProfile//*`  
`keyMaterial InputStream //WLANProfile//*`  
`MacRandomization InputStream //WLANProfile//*`  
`enableRandomization InputStream //WLANProfile//*`

---

<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:15pm UTC](https://forums.powershell.org/t/powershell-xpath-seems-to-be-not-working/21920/5 "2024-05-16T20:15:03Z")

</div>


