XML data to a label.text property

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
User avatar
miketartaglia
Posts: 97
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Mon Feb 02, 2015 7:44 am

Re: XML data to a label.text property

Post by miketartaglia »

xml Servers
--- -------
version="1.0" encoding="utf-8" Servers

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

Re: XML data to a label.text property

Post by jvierra »

You posted the object and not the XML.

$xml.SelectNodes('//Instance/BindingHostName')| select -expand outerXML

You also need to post you XML and not the object display. We need the text in the file. Without it there is no way I can quickly guess at you issue.

This may help you understand XML and what you need to provide:

https://www.w3schools.com/xml/cd_catalog.xml

https://www.w3schools.com/xml/

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

Re: XML data to a label.text property

Post by jvierra »

can not post the XML file as there is information in them that I can not release. I will try to figure out what could be wrong with it. thanks for trying :)
Just post the node of interest and change any I formation that is proprietary.

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

Re: XML data to a label.text property

Post by jvierra »

Another way to exatract the issue is this:

$file.servers.server.Instances.Instance

run that at a prompt to see how many nodes exist. To get the correct node use XPath. If the name you want is an attribute then XPath will do the search:

$file.SelectSingleNode("//Instance[@BindingHostName='$BindingURL']")

With a sample of the "Instance" node I can give you the exact XPath in a second.

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

Re: XML data to a label.text property

Post by miketartaglia »

I just posted the XML node

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

Re: XML data to a label.text property

Post by jvierra »

Post the XML text from the file. The display in PowerShell is of no use.

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

Re: XML data to a label.text property

Post by miketartaglia »

My apologies, the post never saved for some reason. Below is the code for the node. I hope this is what you are looking for.

<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>

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

Re: XML data to a label.text property

Post by jvierra »

Great. Now I can show you.

The following finds and extract a single instance by name.

Code: Select all

[xml]$xml = @'
<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>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>
</Instances>
'@
$xml.SelectSingleNode("//Instance[Name='billybob']").BindingHostName
$xml.SelectSingleNode("//Instance[Name='billybob']") | Select-Object name, version, Licensekey
$node = $xml.SelectSingleNode("//Instance[Name='billybob']")
$node.BindingHostName
Copy and paste it at a prompt to play with the contests of the node.

Remember that XML is case sensitive.

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

Re: XML data to a label.text property

Post by jvierra »

This is how to do what you were originally trying to do.


$bindingHost = 'billybob.nowhere.com'
$xml.SelectSingleNode("//Instance[BindingHostName='$bindingHost']").Name

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

Re: XML data to a label.text property

Post by jvierra »

Looking at the XML your original should have worked so I suspect the XML posted does not include all important bits of the XML like namespaces. You may need to post the complete wrapper including the XML statement and the Servers/Server tags and any namespace declarations or any schema declarations.

Locked