Solved

TransformXML Error

Posted on 2008-06-11
5
971 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
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:vbwizardry
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
try this out oXsl.Load(new XPathDocument(new StringReader(xsl)));
0
 
LVL 7

Expert Comment

by:vbwizardry
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now