Types/OpenPackage.Part/ReadXsd.ps1
|
<# .SYNOPSIS Reads Part Content as Xml Schema Definitions .DESCRIPTION Reads an OpenPackage Part's Content as Xml Schema Definitions #> [Reflection.AssemblyMetadata( 'FilePattern', '\.xsd?$' )] [Reflection.AssemblyMetadata( 'ContentTypePattern', '[/\+]xsd?$' )] param( # An optional input object # If provided, content will be read from this object. # If not provided, content will be read from this part. [Alias('Input')] [PSObject]$InputObject = $null, # Any options used to read the data. [Alias('Options')] [Collections.IDictionary]$Option = [Ordered]@{} ) $xmlReaderSettings = [Xml.XmlReaderSettings]::new() $xmlReaderSettings.DtdProcessing = 'Parse' foreach ($key in $options.Keys) { if ($xmlReaderSettings.psobject.Properties[$key].IsSettable) { $xmlReaderSettings.$key = $option[$key] } } if ($InputObject -is [IO.Stream]) { try { $xmlReader = [Xml.XmlReader]::Create($InputObject, $xmlReaderSettings) [Xml.Schema.XmlSchema]::Read($xmlReader,{}) } catch { $_ } finally { if ($xmlReader) { $xmlReader.Close() $xmlReader.Dispose() } } } elseif ($this.GetStream) { try { $partStream = $this.GetStream('Open','Read') $xmlReader = [Xml.XmlReader]::Create($partStream, $xmlReaderSettings) [Xml.Schema.XmlSchema]::Read($xmlReader,{}) } catch { $_ } finally { if ($xmlReader) { $xmlReader.Close() $xmlReader.Dispose() } $partStream.Close() $partStream.Dispose() } } |