How to determine XML type in Powershell?

I'm writing a script that is supposed to look at the content of a file and determine if it is a (well formed) XML or not. I found a page on [][1] that this is quite easy to do:

>32 -is [int]

The thing is however that I can only test this by casting the left-side for XML files:

>[xml](Get-Content c:\Path\To\xml_file.xml) -is [xml]

...which in this case would be rather pointless: if the file is XML, the casting will already prove this, else throw an exception. I therefore wonder: is there any way to determine XML files in Powershell in a True-False way?


Try the -as operator:

[bool]((Get-Content c:\Path\To\xml_file.xml) -as [xml])

function Is-Valid-XML 
    param ([string] $path)

    $xml = New-Object System.Xml.XmlDocument
        $valid = $true

        $valid = $false

    return $valid

Need Your Help

What (emulated?) architecture does Windows Azure run on?

architecture azure amazon-ec2

EC2 tells you the architecture of their giant instance types (e.g. 2 x Intel Xeon X5570, quad-core “Nehalem” architecture), but refuses to be specific about their small instance types. What about A...