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?
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.
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! ;)
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:
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?
You may want to look into creating an XSLT extension, which takes the JSON url as a paramter and returns XML.
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.
Not sure if Razor is an option, but you can use the full power of C# in there. Would be easier :).
Jeroen
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! ;)
is working on a reply...