Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Cannot convert/save XML with XSLT - VB.net

$
0
0

So I have the XSLT code (it's correct, it's tested separately) and I have it hard-coded as a string (that's a requirement, don't 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:\Users\gk\Desktop\tempXSLTcode.xsl", xsltTransformerCode.transformationXSLTcode())
    'load the xml string taken from the database'
    myXmlDoc.Load("C:\Users\gk\Desktop\XTilbud.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:\Users\gk\Desktop\myXMLfile.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 it's 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...

Viewing all articles
Browse latest Browse all 935

Trending Articles