Jump to content

Xml/xslt Parser With "inline Xml"


kvnmck18
 Share

Recommended Posts

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.

Edited by kvnmck18
Link to comment
Share on other sites

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

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();

Edited by kvnmck18
Link to comment
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...