Schema validation

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

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

using namespace System.Xml.Linq 
 
$path = Resolve-Path "$pshomemodulesISEen-US*-help.xml" 
$xDocument = [XDocument]::Load($path, [LoadOptions]::SetLineInfo) 
 
$xmlSchemaSet = [System.Xml.Schema.XmlSchemaSet]::new() 
$null = $xmlSchemaSet.Add( 
    'http://schemas.microsoft.com/maml/2004/10', 
    "$pshomeSchemasPSMamlmaml.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 the 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
3.144.39.133