Cannot convert/save XML with XSLT - VB.net

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine

So I have the XSLT code (its correct, its tested separately) and I have it hard-coded as a string (thats a requirement, dont bother asking). Loading the XML, the XSLT and all this stuff is OK.

But when I use the XmlDocument as 1st argument in XmlCompiledTransform.Transform() I get exception about White space handling.

Then I use the XmlReader as 1st argument, and this works, but I get exception as I try to save the transformed file, and the exception is Invalid XML document. The document does not have a root element.

Here is the code:
Dim xsltTransformerCode As New xsltTransformCode()
Dim myXmlDoc As New XmlDocument()
Dim resultXmlDoc As New XmlDocument()
Dim sr As New StringReader(xsltTransformerCode.transformationXSLTcode())
Dim xr As XmlReader = XmlReader.Create(sr)
Dim xsltTransCompiled As New XslCompiledTransform()

write the stringified xslt code to file, in order to check its validity manually
File.WriteAllText("C:UsersgkDesktoptempXSLTcode.xsl", xsltTransformerCode.transformationXSLTcode())
load the xml string taken from the database
myXmlDoc.Load("C:UsersgkDesktopXTilbud.xml")
load the stylesheet
xsltTransCompiled.Load(xr)

Using xw As XmlWriter = resultXmlDoc.CreateNavigator().AppendChild()
xsltTransCompiled.Transform(myXmlDoc, Nothing, xw)
xw.Close()
End Using

resultXmlDoc.Save("C:UsersgkDesktopmyXMLfile.xml")

sr.Dispose()
sr.Close()
xr.Close()

P.S. I want to transform the original document and pass its value to another xmlDocument and save it. (Or if I can transform and save the same object, then its ok. I am open for suggestions).

So what I need is somehow to get the value of the reader and save it as XML document or smth like that, I am not sure...


View the full article
 
Back
Top