XML and case sensitivity

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
miketartaglia
Posts: 100
Joined: Mon Feb 02, 2015 7:44 am

XML and case sensitivity

Post by miketartaglia »

$url = "abc.domain.com"
$textboxTenantName.Text = ($file.SelectSingleNode("//Instance[BindingHostName='$url']").Name)

I use this code to look up a node in an XML file that is equal to ABC.domain.com. NOTE: in $URL the full hostname is in lowercase. However, in the SelectSingleNode the BindingHostName could be partially in uppercase, which poses a problem when you don't know what case it is to begin with.

How can I make the $textboxTenantName.Text = 'abc.domain.com' when the BindingHostName is ABC.domain.com?
I hope i explained what I am looking to do clearly. If not, please ask any questions.

Thank you,

Mike

jvierra
Posts: 14481
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: XML and case sensitivity

Post by jvierra »

There are numerous examples of ways t do this here:
https://www.google.com/search?newwindow ... Pq9XJwkGiA

User avatar
miketartaglia
Posts: 100
Joined: Mon Feb 02, 2015 7:44 am

Re: XML and case sensitivity

Post by miketartaglia »

Yea, I have used Google prior to posting here as I always do. I was hoping someone could just give me something that could help with my specific code in this forum to save me a little time and maybe help others looking for a similar solution.

jvierra
Posts: 14481
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: XML and case sensitivity

Post by jvierra »

Which examples did you try and what was the error?

User avatar
miketartaglia
Posts: 100
Joined: Mon Feb 02, 2015 7:44 am

Re: XML and case sensitivity

Post by miketartaglia »

I don't think its going to work, but I had another though.

I am researching on how to search an XML file for the node BindingHostName and change the value or that node to all lowercase. I would imagine this may be simpler for what I am trying to accomplish. Any guidance on this would be appreciated.

The steps would be
1. Search each node of BindingHostName
2. convert each node's value to all lowercase
3. Save XML file

jvierra
Posts: 14481
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: XML and case sensitivity

Post by jvierra »

The following will search all nodes and return the match ignoring the case.

$file.SelectNodes('//Instance[@BindingHostName]') | Where ($_.Name -eq $url)

Locked