Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I have an = sign in an XML?

I have a Powershell script which calls an XML, gets a URL, and tries to open Chrome to that URL. Downside, the URL contains the = character, and none of the character escape suggestions I’ve seen work.

Here’s the XML:

<Config>
    <Stuff>
        <Application Name="Place" CaptivePortal="https://website.com:1337/php/uid.php?thing=1&stuff=0" RDP="192.168.1.1" Entitlement="Admin" />
    </Stuff>
</Config>

And here’s the section of the PS scripts that’s calling it:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Function func_launch_Stuff($v_func_parm_launch_type, $v_func_parm_launch_element){

    # launch based on type
    switch ($v_func_parm_launch_type)
    {
        "URL" {
            $v_Application_Launch = "C:\Program Files\Google\Chrome\Application\chrome.exe"
            $v_Application_Argument = "$($v_func_parm_launch_element)"
            Start-Process -FilePath $v_Application_Launch -ArgumentList $v_Application_Argument -Wait}
}
}

[xml]$v_XML_Config_File = Get-Content -Path $v_parm_XML_Config_File

I’ve trimmed out other sections, because this is the only one throwing errors. I’d go into changing the original script more, but it was hand crafted by an engineer we don’t have anymore, and I’m not good enough with PS to redo this myself in a way that’ll handle my issue without making 10 more.

I’ve tried using the four options from here, and manually replacing the = character with =. It always throws the error below, with X replaced by =, `=, or &.

"Error message: Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "’X‘ is an unexpected token."

>Solution :

Your last line in sample code should be changed…

From:

[xml]$v_XML_Config_File = Get-Content -Path $v_parm_XML_Config_File

To:

[xml]$v_XML_Config_File = Get-Content -Path $v_parm_XML_Config_File | ConvertTo-Xml

I’ve tested sample xml which you posted and got errors, by piping to ConverTo-Xml it worked.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading