Schema validation

LINQ to XML can be used to validate an XML document against a schema file.

.NET Core and schema validation

.NET Core appears to be unwilling to expand include references in an XML schema. This apparent bug is exhibited in PowerShell Core. Windows PowerShell will produce schema validation errors; PowerShell Core will not at this time.

The ISE-help.xml XML document is validated against its schema in the following example:

using namespace System.Xml.Linq 
 
$path = 'C:WindowsSystem32WindowsPowerShellv1.0modulesISEen-USPSISE-help.xml'
$xDocument = [XDocument]::Load(
$path,
[LoadOptions]::SetLineInfo
) $xmlSchemaSet = [System.Xml.Schema.XmlSchemaSet]::new() $null = $xmlSchemaSet.Add( 'http://schemas.microsoft.com/maml/2004/10', 'C:WindowsSystem32WindowsPowerShellv1.0SchemasPSMamlmaml.xsd' )
[System.Xml.Schema.Extensions]::Validate( $xDocument, $xmlSchemaSet, { param($sender, $eventArgs) if ($eventArgs.Severity -in 'Error', 'Warning') { Write-Host $eventArgs.Message Write-Host (' At {0} column {1}' -f $sender.LineNumber, $sender.LinePosition ) } } )

Positional information is made available by loading XDocument with the SetLineInfo option.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.95.244