Hi.
I am using the transform method to create an HTML file using an existing XML Document and an XLST. I need to use XPath to extract
a node from my XML Document and my XLST document will format the node into something readable to my users.
My code works, however, I will be having multiple users calling my routines at the same time. So I don't want to create a "hard"
copy of my html file and place on my server. Because every time a new user calls the routine it will overwrite the html file.
I'd rather have the html file be virtual on each users web browser.
My question is, I'm not sure where I need to change my code. I have tried several variations of the XslTransform sending
different parameters but nothing is getting me the desired result. And I am unsure if it is my XslTranform call, or if I need to
change my writer class or if my webform actually needs additional objects to "virtually" display the html file. I am at a lose as
to where I look for the answer.
Thank you in advance for any help. Below please find my code behind for my form that actually creates an HTML file on my web server.
//Read in textbox value
string userInput = TextBox1.Text.T rim();
// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver( );
resolver.Creden tials = System.Net.Cred entialCache.Def aultCredentials ;
XslTransform xslt = new XslTransform();
xslt.Load(Serve r.MapPath("XSLT File.xsl"),reso lver);
XmlDocument doc = new XmlDocument();
doc.Load(Server .MapPath("XMLFi le.xml"));
//Get Node 1
XmlNodeList N1NodeList = doc.DocumentEle ment.SelectNode s("//N1");
XmlNode N1 = N1NodeList.Item (0);
//using XPath to search a node for the user Inputted Value
string y = "//N2[N2C1 = '" + userInput + "']";
XmlNodeList testNodeList = doc.DocumentEle ment.SelectNode s(y);
string x = testNodeList.Co unt.ToString(); // If NodeList exists
int i = testNodeList.Co unt;
if (i >= 1) //need to throw error if group id is not found.
{
XmlNode testNode = testNodeList.It em(0);
//Move within the tree.
testNode.Prepen dChild(busDate) ;
XmlDocument tmpDoc = new XmlDocument();
tmpDoc.LoadXml( testNode.OuterX ml);
// Now big question. Multi-threading - multiple users -- writing a file to system. Rather have it dynamic.
XmlTextWriter writer = new XmlTextWriter(S erver.MapPath(" asucPartial.htm l"), null);
xslt.Transform( tmpDoc,null,wri ter,resolver);
writer.Close();
Label1.Text = "done";
}
else
{
x = "Record Not Found.";
Label1.Text = x;
}
}
I am using the transform method to create an HTML file using an existing XML Document and an XLST. I need to use XPath to extract
a node from my XML Document and my XLST document will format the node into something readable to my users.
My code works, however, I will be having multiple users calling my routines at the same time. So I don't want to create a "hard"
copy of my html file and place on my server. Because every time a new user calls the routine it will overwrite the html file.
I'd rather have the html file be virtual on each users web browser.
My question is, I'm not sure where I need to change my code. I have tried several variations of the XslTransform sending
different parameters but nothing is getting me the desired result. And I am unsure if it is my XslTranform call, or if I need to
change my writer class or if my webform actually needs additional objects to "virtually" display the html file. I am at a lose as
to where I look for the answer.
Thank you in advance for any help. Below please find my code behind for my form that actually creates an HTML file on my web server.
//Read in textbox value
string userInput = TextBox1.Text.T rim();
// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver( );
resolver.Creden tials = System.Net.Cred entialCache.Def aultCredentials ;
XslTransform xslt = new XslTransform();
xslt.Load(Serve r.MapPath("XSLT File.xsl"),reso lver);
XmlDocument doc = new XmlDocument();
doc.Load(Server .MapPath("XMLFi le.xml"));
//Get Node 1
XmlNodeList N1NodeList = doc.DocumentEle ment.SelectNode s("//N1");
XmlNode N1 = N1NodeList.Item (0);
//using XPath to search a node for the user Inputted Value
string y = "//N2[N2C1 = '" + userInput + "']";
XmlNodeList testNodeList = doc.DocumentEle ment.SelectNode s(y);
string x = testNodeList.Co unt.ToString(); // If NodeList exists
int i = testNodeList.Co unt;
if (i >= 1) //need to throw error if group id is not found.
{
XmlNode testNode = testNodeList.It em(0);
//Move within the tree.
testNode.Prepen dChild(busDate) ;
XmlDocument tmpDoc = new XmlDocument();
tmpDoc.LoadXml( testNode.OuterX ml);
// Now big question. Multi-threading - multiple users -- writing a file to system. Rather have it dynamic.
XmlTextWriter writer = new XmlTextWriter(S erver.MapPath(" asucPartial.htm l"), null);
xslt.Transform( tmpDoc,null,wri ter,resolver);
writer.Close();
Label1.Text = "done";
}
else
{
x = "Record Not Found.";
Label1.Text = x;
}
}
Comment