kvnmck18 Posted May 12, 2009 Share Posted May 12, 2009 My code is below. I know my issue is with the "MapPath" I have tried to using XmlTextReader along with StringReader but I have had no success. Should I make the XML into an object? <%@ Import Namespace="System.Xml" %><%@ Import Namespace="System.Xml.Xsl" %><%@ Import Namespace="System.Xml.XPath" %><%@ Import Namespace="System.IO" %><%@ Import Namespace="System.Text" %><%@ Import Namespace="System" %><%@ Import Namespace="System.Net" %><script language="C#" runat="server"> public void Page_Load(Object sender, EventArgs E) { string xml = "<all><node>TEST</node></all>"; string xmlPath = Server.MapPath(xml); string xslPath = Server.MapPath("XSL.xsl"); string id = Request.QueryString["id"]; XsltArgumentList args = new XsltArgumentList(); args.AddParam("id", "", id); FileStream fs = new FileStream(xmlPath, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(fs, Encoding.UTF8); XmlTextReader xmlReader = new XmlTextReader(reader); XPathDocument doc = new XPathDocument(xmlReader); XslTransform xslDoc = new XslTransform(); xslDoc.Load(xslPath); xslDoc.Transform(doc, args, Response.Output); reader.Close(); xmlReader.Close(); }</script> Thanks in advance. Link to comment Share on other sites More sharing options...
jesh Posted May 12, 2009 Share Posted May 12, 2009 Yeah, you can't map a path on the server to "<all><node>TEST</node></all>".You can, however, create an XPathDocument using any stream that you want, including the stream that exists in the StringReader: public void Page_Load(Object sender, EventArgs E){ // Prepare an XPathDocument object. string xml = "<all><node>TEST</node></all>"; StringReader reader = new StringReader(xml); XPathDocument doc = new XPathDocument(reader); // And then prepare an XslTransform object. string xslPath = Server.MapPath("XSL.xsl"); string id = Request.QueryString["id"]; XsltArgumentList args = new XsltArgumentList(); args.AddParam("id", "", id); XslTransform xslDoc = new XslTransform(); xslDoc.Load(xslPath); // Transform the XPathDocument object. xslDoc.Transform(doc, args, Response.Output);} Link to comment Share on other sites More sharing options...
kvnmck18 Posted May 12, 2009 Author Share Posted May 12, 2009 I just tried this too... and no success: string xml = "<all><node>TEST</node></all>"; string xslPath = Server.MapPath("XSL.xsl"); string id = Request.QueryString["id"]; XsltArgumentList args = new XsltArgumentList(); args.AddParam("id", "", id); ////////// UTF8Encoding xmlUTF = new UTF8Encoding(); byte[] byteXML = xmlUTF.GetBytes(xml); MemoryStream stream = new MemoryStream(byteXML); XmlTextReader xmlReader = new XmlTextReader(stream); //FileStream fs = new FileStream(xmlPath, FileMode.Open, FileAccess.Read); //StreamReader reader = new StreamReader(fs, Encoding.UTF8); // XmlTextReader xmlReader = new XmlTextReader(reader); XPathDocument doc = new XPathDocument(xmlReader); XslTransform xslDoc = new XslTransform(); xslDoc.Load(xslPath); xslDoc.Transform(doc, args, Response.Output); stream.Close(); //reader.Close(); xmlReader.Close(); Link to comment Share on other sites More sharing options...
kvnmck18 Posted May 13, 2009 Author Share Posted May 13, 2009 jesh, thanks for your response. I don't know why - but that seems to be working.... I know I tried that before. I probably just had a server-cache. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.