Try parsing text as XML, and validating it if a schema is provided.
Test-Xml.ps1 [-Path] <String> [-Schemata <Hashtable>] [-SkipValidation] [-Warnings] [-ErrorMessage]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
Test-Xml.ps1 -Xml <String> [-Schemata <Hashtable>] [-SkipValidation] [-Warnings] [-ErrorMessage]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
'
False
A file to check.
Type: String
Parameter Sets: Path
Aliases: FullName
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
The string to check.
Type: String
Parameter Sets: Xml
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
A hashtable of schema namespaces to schema locations (in addition to the xsi:schemaLocation attribute).
Type: Hashtable
Parameter Sets: (All)
Aliases: Schemas
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Indicates that XML Schema validation should not be performed, only XML well-formedness will be checked.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: NoValidation
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Type: SwitchParameter
Parameter Sets: (All)
Aliases: ShowWarnings
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
When present, returns the well-formedness or validation error messages instead of a boolean value, or nothing if successful. This effectively reverses the truthiness of the return value.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: NotSuccessful
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
https://www.w3.org/TR/xmlschema-1/#xsi_schemaLocation
https://docs.microsoft.com/dotnet/api/system.xml.xmlresolver
https://docs.microsoft.com/dotnet/api/system.xml.schema.validationeventhandler