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.
This topic is 5 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
mtartaglia
Posts: 101
Last visit: Mon Dec 19, 2022 11:45 am

XML and case sensitivity

Post by mtartaglia »

$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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
mtartaglia
Posts: 101
Last visit: Mon Dec 19, 2022 11:45 am

Re: XML and case sensitivity

Post by mtartaglia »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: XML and case sensitivity

Post by jvierra »

Which examples did you try and what was the error?
User avatar
mtartaglia
Posts: 101
Last visit: Mon Dec 19, 2022 11:45 am

Re: XML and case sensitivity

Post by mtartaglia »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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)
This topic is 5 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked