#Input file
[xml]$xml = (Get-Content ExportedDocumentation.xml)
#Extract nodes with types
$types = $xml.SelectNodes("doc/members/member[starts-with(@name,'T:')]")
Function ExtractText($node)
{
if ($node -is [System.Xml.XMLElement])
{
[string]$text = $node.InnerXml
}
else
{
[string]$text = $node
}
if ($text)
{
#Remove and tags
$text = [Regex]::Replace($text, '?c>', '')
#Extract type name from tag
$text = [Regex]::Replace($text, '[a-zA-Z0-9_]*)"[ \n]*/>', '${ref}')
#Remove line breaks and suppress repeated whitespaces
$text = [Regex]::Replace($text, '[\n ]+', ' ')
$text = $text.Trim()
}
return $text
}
#Fill texts to object properties
$doc = $types | % {New-Object PSObject -Property @{
ClassName = ($_.name).SubString(2) #Omit "T:"
Summary = ExtractText $_.summary
Remarks = ExtractText $_.remarks}}
#Create Word document
$word = New-Object -ComObject Word.Application
$word.Visible = $true
$range = $word.Documents.Add().Range()
foreach ($item in $doc)
{
#Class name
$range.Text = "Class $($item.ClassName)"
$range.Style = "Heading 3"
$range.InsertParagraphAfter()
$range.SetRange($range.End, $range.End)
if ($item.Summary)
{
#Summary
$range.Text = $item.Summary
$range.Style = "Normal"
$range.InsertParagraphAfter()
$range.SetRange($range.End, $range.End)
}
if ($item.Remarks)
{
#Remarks (title)
$range.Text = "Remarks:"
$range.Style = "Normal"
$range.InsertParagraphAfter()
$range.SetRange($range.End, $range.End)
#Remarks (text)
$range.Text = $item.Remarks
$range.Style = "Emphasis"
$range.InsertParagraphAfter()
$range.SetRange($range.End, $range.End)
}
}