Solved

TransformXML Error

Posted on 2008-06-11
5
982 Views
Last Modified: 2012-08-13
I am trying to transform XML with an XSL style sheet.

I read the XML and the XSL from a database, and then need to transform them together to generate HTML output.

When I try to load the XSL string I get the error:
System.UriFormatException was unhandled by user code
  Message="Invalid URI: The Uri string is too long."

CODE
//-----------------------
            XmlDocument oXml = new XmlDocument();
            XslCompiledTransform oXsl = new XslCompiledTransform();

            string transformedXML = string.Empty;
            string xsl = GetXLSByName(name);
            string xml = GetXMLbyShop(shopID, viewTime);
           
            oXml.LoadXml(xml);
            xsl = xsl.Replace(System.Environment.NewLine, "<br/>");
            oXsl.Load(xsl);

            oXsl.Transform(xml, transformedXML);
0
Comment
Question by:Rowdyone52
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:vbwizardry
ID: 21763107
XslCompiledTransform.Load (String) - Loads and compiles the style sheet located at the specified URI.
In your case it looks like you are providing the content of and not the path to the style sheet.
0
 

Author Comment

by:Rowdyone52
ID: 21763122
I dont have a file, I have it stored in a string, is there a way to load the string?
0
 

Author Comment

by:Rowdyone52
ID: 21763304
I am trying to load this strings like below, however I am getting no return for the writer
----
            string xslContent = GetXLSByName(name);
            string xmlContent = GetXMLbyShop(shopID, viewTime);
            xmlContent = xmlContent.Replace(System.Environment.NewLine, "<br/>");

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xmlContent);

            XslCompiledTransform transformer = new XslCompiledTransform();
            transformer.Load(new XmlTextReader(new StringReader(xslContent)));
            StringWriter writer = new StringWriter();

            transformer.Transform(xmlDoc,null,writer);

            Console.WriteLine(writer.ToString());

            return writer.ToString();
0
 
LVL 7

Accepted Solution

by:
vbwizardry earned 500 total points
ID: 21763328
try this out oXsl.Load(new XPathDocument(new StringReader(xsl)));
0
 
LVL 7

Expert Comment

by:vbwizardry
ID: 21763405
if you getting no return you probably have problem within your style sheet. It is not matching data in your XML document. I would output both the xml doc and xsl and use VS IDE to debug it.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question