blondebier
Programmer
Greetings XML/XSL gurus!
I'm trying to perform an XSL transform in vb.net.
I have written an XSL that changes the structure of some XML, performs some calculations on it, and outputs a new XML file.
I need this process to be done in vb.net.
I have written the following code to do the job.
Try
Dim XSLTransform As New Xsl.XslTransform
Dim transformedXML As New Xml.XmlDocument
Dim XSLfilepath As String
XSLfilepath = Server.MapPath("myXSL.xsl")
Dim sw As New StringWriter
XSLTransform.Load(XSLfilepath)
XSLTransform.Transform(submissionXML, Nothing, sw, Nothing)
transformedXML.LoadXml(sw.ToString)
return transformedXML
Catch Ex As Exception
MsgBox("Error:" & Ex.ToString)
End Try
PROBLEM: The new XML that is generated has the following header;
<?xml version="1.0" encoding="utf-16"?>
I don't want it to be utf-16 I need it to be utf-8.
Apparently this is the standard encoding returned for a StringWriter object and it cannot be changed.
My second option was to output the new XML into a XmlTextWriter. This is works great, I can change the output encoding to UTF-8 by declaring it as
Dim xtw As XmlWriter = New XmlTextWriter(pathToWriteXML, System.Text.Encoding.UTF8)
But I have to write the darn XML to a file. I don't want it in a file, I want it in a domXML object.
This is so frustrating. (I'm pulling my hair out!)
If anyone has cracked this problem I would love to hear from you.
Cheers,
Francis
I'm trying to perform an XSL transform in vb.net.
I have written an XSL that changes the structure of some XML, performs some calculations on it, and outputs a new XML file.
I need this process to be done in vb.net.
I have written the following code to do the job.
Try
Dim XSLTransform As New Xsl.XslTransform
Dim transformedXML As New Xml.XmlDocument
Dim XSLfilepath As String
XSLfilepath = Server.MapPath("myXSL.xsl")
Dim sw As New StringWriter
XSLTransform.Load(XSLfilepath)
XSLTransform.Transform(submissionXML, Nothing, sw, Nothing)
transformedXML.LoadXml(sw.ToString)
return transformedXML
Catch Ex As Exception
MsgBox("Error:" & Ex.ToString)
End Try
PROBLEM: The new XML that is generated has the following header;
<?xml version="1.0" encoding="utf-16"?>
I don't want it to be utf-16 I need it to be utf-8.
Apparently this is the standard encoding returned for a StringWriter object and it cannot be changed.
My second option was to output the new XML into a XmlTextWriter. This is works great, I can change the output encoding to UTF-8 by declaring it as
Dim xtw As XmlWriter = New XmlTextWriter(pathToWriteXML, System.Text.Encoding.UTF8)
But I have to write the darn XML to a file. I don't want it in a file, I want it in a domXML object.
This is so frustrating. (I'm pulling my hair out!)
If anyone has cracked this problem I would love to hear from you.
Cheers,
Francis