My original question was how to get that output of just the Name from that Instance node into the $detailsLBL control text property. It still doesn't work. It still shows up as BLANK.
$buttonSEARCH_Click= {
#TODO: Place custom script here
[xml]$file = (Get-Content 'c:\test\programdata\Server Configuration.xml')
$detailsLBL.Text = $file.SelectSingleNode("//Instance[BindingHostName='$BindingURL']").Name
}
XML data to a label.text property
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.
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.
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: XML data to a label.text property
Without a good and correct example of the XML I cannot help you.
My example works. Run this and you will see that it works.
Without accurate information about your XML there is no way to know why this would fail. If you have namespaces in the XML then the namespaces must be resolved to access the contents of the XML.
My example works. Run this and you will see that it works.
Code: Select all
[xml]$xml = @'
<Servers>
<Server>
<Instances>
<Instance>
<Name>billybob</Name>
<Version>8.26.0.0</Version>
<InstalledVersion>8.26.0.0</InstalledVersion>
<LicenseKey>111-222-333-44444</LicenseKey>
<AppPoolName>billybob</AppPoolName>
<BindingHostName>billybob.nowhere.com</BindingHostName>
<UseSSLBinding>false</UseSSLBinding>
<ShipmentServerEndPoint />
<BindingSSLCertificate>
<RequireServerNameIdentification>false</RequireServerNameIdentification>
<Issuer />
<SerialNumber />
<Storage />
<SslStatus>Synchronized</SslStatus>
</BindingSSLCertificate>
<AuthenticationMode>Forms</AuthenticationMode>
</Instance>
<Instance>
<Name>bobbyjoe</Name>
<Version>8.26.0.0</Version>
<InstalledVersion>8.26.0.0</InstalledVersion>
<LicenseKey>111-222-333-44444</LicenseKey>
<AppPoolName>bobbyjoe</AppPoolName>
<BindingHostName>bobbyjoe.nowhere.com</BindingHostName>
<UseSSLBinding>false</UseSSLBinding>
<ShipmentServerEndPoint />
<BindingSSLCertificate>
<RequireServerNameIdentification>false</RequireServerNameIdentification>
<Issuer />
<SerialNumber />
<Storage />
<SslStatus>Synchronized</SslStatus>
</BindingSSLCertificate>
<AuthenticationMode>Forms</AuthenticationMode>
</Instance>
</Instances>
</Server>
</Servers>
'@
$BindingURL = 'billybob.nowhere.com'
$textName = $xml.SelectSingleNode("//Instance[BindingHostName='billybob.nowhere.com']").Name
$textName
Re: XML data to a label.text property
In this example the variable is never set in the code. It is null so you will get back nothing.miketartaglia wrote: ↑Wed Feb 20, 2019 6:53 pm My original question was how to get that output of just the Name from that Instance node into the $detailsLBL control text property. It still doesn't work. It still shows up as BLANK.
$buttonSEARCH_Click= {
#TODO: Place custom script here
[xml]$file = (Get-Content 'c:\test\programdata\Server Configuration.xml')
$detailsLBL.Text = $file.SelectSingleNode("//Instance[BindingHostName='$BindingURL']").Name
}
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: XML data to a label.text property
$BindingURL is set in a text box. Sorry I forgot to explain this. When someone clicks the SEARCH button it runs the $buttonSEARCH_Click code. I must be doing something wrong with the GUI as it works fine in a powershell command window.jvierra wrote: ↑Wed Feb 20, 2019 7:24 pmIn this example the variable is never set in the code. It is null so you will get back nothing.miketartaglia wrote: ↑Wed Feb 20, 2019 6:53 pm My original question was how to get that output of just the Name from that Instance node into the $detailsLBL control text property. It still doesn't work. It still shows up as BLANK.
$buttonSEARCH_Click= {
#TODO: Place custom script here
[xml]$file = (Get-Content 'c:\test\programdata\Server Configuration.xml')
$detailsLBL.Text = $file.SelectSingleNode("//Instance[BindingHostName='$BindingURL']").Name
}
Re: XML data to a label.text property
Why are you using a variable when the data is in a textbox. Just use the textbox.
I suspect you have a scope issue which is the reason we don't use interim variables in a form. Check the variable. It is likely null.
I suspect you have a scope issue which is the reason we don't use interim variables in a form. Check the variable. It is likely null.
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: XML data to a label.text property
The textbox is named BindingURL. I thought that was considered a variable when using it in code. My mistake. So since $BindingURL is NULL that makes sense. I think I am back in rookie status then
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: XML data to a label.text property
The problem is that it still shows up as NULL or blank. It starts off with a value of "TEXT" (I set that up for troubleshooting) after I click the button (the code you have already seen), it switches to NULL. So we probed that your code works, but I can not make the value of that specific output to be in the $detailsLBL value.
Does that make sense?
Does that make sense?
Re: XML data to a label.text property
No that doesn't make any sense.
What has a value of "TEXT"?
What switches to NULL?
What code have you changed?
What is $detailsBL?
Without your code none of this makes any sense.
What is in the variable "$BindingURL'"? It is null.
What has a value of "TEXT"?
What switches to NULL?
What code have you changed?
What is $detailsBL?
Without your code none of this makes any sense.
What is in the variable "$BindingURL'"? It is null.
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: XML data to a label.text property
jvierra wrote: ↑Thu Feb 21, 2019 9:39 am No that doesn't make any sense.
What has a value of "TEXT"? detailsLBL - This is the label where I want the value of the XML code you wrote to show as the .NAME at the end of the XML line.
What switches to NULL? detailsLBL switches to NULL instead of the .NAME above.
What code have you changed? None
What is $detailsBL? this is a label that I want to display the value mentioned above.
Without your code none of this makes any sense. You should already have the code in this long thread
What is in the variable "$BindingURL'"? It is null. This is the value of a text box that I am typing in a URL that needs to be pulled out of the XML file and set the detailsLBL.TEXT to the .NAME mentioned above.