¿Qué tipo de excepción se debe usar en Powershell para detectar un error de análisis XML debido a caracteres no válidos?
La línea 2 en el siguiente script genera:
"No se puede convertir el valor" System.Object [] "para escribir" System.Xml.XmlDocument ". Error:" '→', el valor hexadecimal 0x1A, no es un carácter válido. Línea 39, posición 23. "
En línea: 1 char: 8 + [xml] $ x <<<< = Get-Content 4517.xml + CategoryInfo: MetadataError: (:) [], ArgumentTransformationMetadataException + FullyQualifiedErrorId: RuntimeException "
¿Qué excepción se debe especificar en la línea 4 (del script) para detectar el error mencionado anteriormente?
<code>try { [xml]$xml = Get-Content $file # line 2 } catch [?] { # line 4 echo "XML parse error!" # handle the parse error differently } catch { echo $error # some general error } </code>
Gracias por mirar (y responder)
Adrián