I am trying to transform an XML file with an XSL file using Powershell .Net method.
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform
$xslt.Load("C:\Users\admin\Downloads\recoveryHistory_en.xsl")
I get the below error message.
PSMessageDetails :
Exception : System.Management.Automation.MethodInvocationException: Exception calling "Load" with "1" argument(s): "XSLT compile error." ---> System.Xml.Xsl.XslLoadException: XSLT compile error. --->
System.Xml.XmlException: For security reasons DTD is prohibited in this XML document. To enable DTD processing set the DtdProcessing property on XmlReaderSettings to Parse and pass the settings into
XmlReader.Create method.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.Xsl.Xslt.XsltInput.ReadTextNodes()
at System.Xml.Xsl.Xslt.XsltInput.ReadNextSibling()
at System.Xml.Xsl.Xslt.XsltInput.FindStylesheetElement()
at System.Xml.Xsl.Xslt.XsltLoader.LoadDocument()
at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)
--- End of inner exception stack trace ---
at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)
at System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object stylesheet, XmlResolver xmlResolver)
at System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet, XmlResolver xmlResolver, QilExpression& qil)
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at CallSite.Target(Closure , CallSite , Object , String )
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo)
at CallSite.Target(Closure , CallSite , Object , String )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject :
CategoryInfo : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : XslLoadException
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
I set the DTDProcessing to Parse as the error pointed out, but still no luck.
[System.Xml.XmlReaderSettings]$xml=New-Object System.Xml.XmlReaderSettings
$xml.DtdProcessing = 'Parse'
$xml
Async : False
NameTable :
XmlResolver :
LineNumberOffset : 0
LinePositionOffset : 0
ConformanceLevel : Document
CheckCharacters : True
MaxCharactersInDocument : 0
MaxCharactersFromEntities : 0
IgnoreWhitespace : False
IgnoreProcessingInstructions : False
IgnoreComments : False
ProhibitDtd : False
DtdProcessing : Parse
CloseInput : False
ValidationType : None
ValidationFlags : ProcessIdentityConstraints, AllowXmlAttributes
Schemas : System.Xml.Schema.XmlSchemaSet
I spotted a lot of questions in this forum similar to mine (transforming xml to html using xslt, How can I bind tag id when convert Xml to Html with Xslt, What is the syntax for converting XML to HTML using PSCX Convert-XML?, Using PowerShell to convert XML to HTML). I tried some of them (for example: convert-xml, validating the xml file content etc.,). Does anyone anyone have a clue on what's with the error message and what could be wrong?