Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nikolas van Etten 202 posts 162 karma points
    Mar 04, 2012 @ 11:24
    Nikolas van Etten
    0

    Creating XmlDocument in XSLT (using inline C#)

    I need to pull some data from an external site and I'm doing so by using the HTML Agility Pack. The data itself is a JSON which is basically just a small part of a large javascript inside the html page. What I want to do is convert the JSON to XML in order to use it more easily within the XSLT file, and I found that Json.NET should do the trick, but as it needs to create the XML as a "real" XmlDocument it causes the XSLT validator to return the following error:

    System.InvalidOperationException: This document already has a 'DocumentElement' node.

    Basically I only need the JSON string converted to an XML string, as I can afterwards easily convert it to a node-set. Anyone know how to accomplish this?

     

  • Asif Malik 203 posts 339 karma points
    Mar 04, 2012 @ 14:26
    Asif Malik
    0

    You may want to look into creating an XSLT extension, which takes the JSON url as a paramter and returns XML.

  • Nikolas van Etten 202 posts 162 karma points
    Mar 04, 2012 @ 16:49
    Nikolas van Etten
    0

    Kinda hoping to avoid that as it's a quite cachable thing and I didn't want to spend more time than needed. But yes, I know that will be an option which should work.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 04, 2012 @ 17:08
    Jeroen Breuer
    0

    Not sure if Razor is an option, but you can use the full power of C# in there. Would be easier :).

    Jeroen

  • Nikolas van Etten 202 posts 162 karma points
    Mar 04, 2012 @ 20:52
    Nikolas van Etten
    0

    My mistake! ;) Turns out the Json itself was the problem and that I just assumed the error was thrown due to the code being inside the XSLT file. So much for working late hours during the weekend... ;)

    Thanks for all help anyway! And yes...Razor it is...next time! ;)

Please Sign in or register to post replies

Write your reply to:

Draft