0

I created a simple PowerShell script to fix RDLC report definition by reverting from 2016 to 2008 version based on knowledge I found somewhere around here. However, the XML namespace is point to http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition which I'm afraid that someday it won't be available for some reasons. Kindly suggest on how to make this script work without relying on external/3rd party assets. For example, which files that I need to host on my web server. Thank you.

PS. I followed the link, but it's not a JSON nor XML format. Just a web page, so I lost there.

param (
    [Parameter(Mandatory=$true)][string]$rptName
)


$file = (Get-Content $rptName)
$rptNameTarget = "Fixed_" + $rptName

# Take out unwanted tags
$file = $file -replace '<ReportSections>',""
$file = $file -replace '<ReportSection>',""
$file = $file -replace '</ReportSection>',""
$file = $file -replace '</ReportSections>',""

# Parse the XML doc
$xml = [xml]$file;

# Set the XML namespace
$xml.Report.xmlns = "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition";

# Remove ReportParametersLayout node
if ($xml.Report.ReportParametersLayout -ne $null) {
    Write-Host "Removing ReportParametersLayout tags.."
    $xml.Report.RemoveChild($xml.Report.ReportParametersLayout);
}

# Save the file to new filename
$xml.save($rptNameTarget)
vonPryz
  • 22,996
  • 7
  • 54
  • 65
user10268539
  • 149
  • 1
  • 1
  • 11
  • 1
    That's not how XML namespaces work. Even if there's an URI, it's just to make the namespace unique. Parsing an XML document does not require network connection to the server "hosting" the namespace. – vonPryz Dec 27 '21 at 10:13
  • vonPryz is right. Take a moment to learn about namespaces, and XSL and you'll have it solved. – William Walseth Dec 27 '21 at 11:24
  • I tried running this script and .RDLC report on local ASP.NET server without Internet connection, it worked correctly. Just realized this fact. Thanks for your comments. – user10268539 Dec 28 '21 at 09:56

0 Answers0