472,145 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

PLEASE explain xmlDocument on server, but the html transform on client???

If someone could just explain this to me...I just don't get it!

I have an aspx page where I retrieve several session variables and use
xmlDocument to transform xml file with xsl file into an instruction
document (not data based) - same as using an xml web control.

The resulting html is on the client? but what about the server side of
things? Trying to figure out how to change and save the xmlDocument.
It I put a button OUTSIDE of the html transform but inside the aspx
page, could I change and save the xmlDoc that way?

Sorry to be so dense about this...PLEASE help me out with explanation
and hopefully an example (again, please don't use datagrid, database
structure data, I'm using text documents as in publishing.

Many thanks,

Kathy
Nov 11 '05 #1
5 3461
You can transform the XML on the server without rendering it to the client.
If the result of the transformation is well-formed XML, then you can load it
into an XmlDocument class and save it as needed.

Can you give some more background for your question?
--
Kirk Allen Evans
www.xmlandasp.net
Read my web log at http://weblogs.asp.net/kaevans
"KathyB" <Ka**********@attbi.com> wrote in message
news:75*************************@posting.google.co m...
If someone could just explain this to me...I just don't get it!

I have an aspx page where I retrieve several session variables and use
xmlDocument to transform xml file with xsl file into an instruction
document (not data based) - same as using an xml web control.

The resulting html is on the client? but what about the server side of
things? Trying to figure out how to change and save the xmlDocument.
It I put a button OUTSIDE of the html transform but inside the aspx
page, could I change and save the xmlDoc that way?

Sorry to be so dense about this...PLEASE help me out with explanation
and hopefully an example (again, please don't use datagrid, database
structure data, I'm using text documents as in publishing.

Many thanks,

Kathy

Nov 11 '05 #2

Kirk,

Thank you SO much for answering...

I have a well formed (of course) xml file that when transformed with an
xsl stylesheet presents the user with a very prettily formatted document
of mfg process steps to follow.

There are some input boxes (e.g., in the xsl if the element <measure>
exists, xsl creates an input box) where when the user enters something,
I need to save it as part of the new document file (a record of what the
user has done).

Whenever I read things about this, it always says must do that stuff
"client side" via javascript. Of course, I realize I have to use
javascript, but don't get why if I'm using a .net xml web control to
specify the xml source and xsl transform file, that I'm now on client!
Of course, I realize asp.net results in html to the browser...sort of!!!

PLEASE show me an example of saving user-entered info within the
xmlDocument class? I don't want to save a "node" but the entire
document. See what I mean? Perhaps how to save the xmlDoc from within
the html javascript code?

Again, thanks for responding! I really appreciate it.

Kathy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 11 '05 #3
Kirk,

Also, how is "transforming the XML on the server without rendering it to
the client" possible, I thought if you did that (xml and xsl) it
automatically gets sent to the client as HTML...I feel so stupid!

Then "If the result of the transformation is well-formed XML, then you
can load it into an XmlDocument class and save it as needed." Again, I
thought that transforming it within xml control WAS loading it into an
xmlDoc...?

Thanks.
KathyBurke

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 11 '05 #4
Probably the first thing to nail down is what happens on the server versus
what happens on the client. On the server, you have an XML file and an XSLT
file. You load the XML file up into an XmlDocument class, load up an
XslTransform, and perform the transformation using XslTransform.Transform.
Does your code look kind of like this? Or are you using the asp:Xml control
to do the transformation?
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(Server.MapPath("data/xmlfile1.xml"));
System.Xml.Xsl.XslTransform trans = new System.Xml.Xsl.XslTransform();
trans.Load(Server.MapPath("xslt/xsltfile1.xslt"));
//transform the results directly to the output stream
trans.Transform(doc,null,Response.OutputStream,new
System.Xml.XmlUrlResolver());
From your description, I am guessing that the result of the transformation
is HTML, and you send the HTML to the client in the HTTP Response. You can
confirm this simply by viewing the page source in the browser.

Now that you have HTML in the browser, the HTML is parsed and the UI you see
with input boxes and buttons is rendered. As you input data into the UI
elements, you want that data to be sent *back to the server*, where the data
is saved? If this is the case, then this is completely possible. Or do you
want to save the data locally to the client's machine? If this is the case,
then this is not possible, since script in the browser purposefully does not
support file I/O.

Let's assume that you have an XML document that you want to update with the
values that the user was working with. There are a couple ways you can do
this.

One way is to use the Request.Form collection to read the values directly
out of the post.

System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(Server.MapPath("data/xmlfile1.xml"));
if(!IsPostBack)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(Server.MapPath("data/xmlfile1.xml"));
System.Xml.Xsl.XslTransform trans = new System.Xml.Xsl.XslTransform();
trans.Load(Server.MapPath("xslt/xsltfile1.xslt"));
//transform the results directly to the output stream
trans.Transform(doc,null,Response.OutputStream,new
System.Xml.XmlUrlResolver());
}
else
{
System.Xml.XmlNode node = doc.SelectSingleNode("Customer/@ID");
node.Value = Request.Form["txtCustomerID"];
doc.Save(Server.MapPath("data/newxmlfile1.xml"));
}

Note that all of this code runs *completely on the server*. The net effect
of this code is to emit HTML back to the client within the HTTP response.
The client's browser knows nothing about XmlDocument.

You can also use client-side JavaScript to do lots of cool stuff, including
using a client-side IE Web Service Behavior that can call web services from
client-side JavaScript. You can also use IE Data Islands and work with XML.
You can create an MSXML.DOMDocument object on the client and work with XML,
then use the MSXML.XMLHTTP class to post the data to your web server. There
is lots of stuff you might do on the client, but the real question is "do
you really need to?" The example above shows how to update the XML document
using the XmlDocument class, is that enough? Or do you really need lots of
client-side JavaScript to manipulate the DOM in the client?
--
Kirk Allen Evans
www.xmlandasp.net
Read my web log at http://weblogs.asp.net/kaevans

"Kathy Burke" <ka**********@attbi.com> wrote in message
news:#A**************@tk2msftngp13.phx.gbl...

Kirk,

Thank you SO much for answering...

I have a well formed (of course) xml file that when transformed with an
xsl stylesheet presents the user with a very prettily formatted document
of mfg process steps to follow.

There are some input boxes (e.g., in the xsl if the element <measure>
exists, xsl creates an input box) where when the user enters something,
I need to save it as part of the new document file (a record of what the
user has done).

Whenever I read things about this, it always says must do that stuff
"client side" via javascript. Of course, I realize I have to use
javascript, but don't get why if I'm using a .net xml web control to
specify the xml source and xsl transform file, that I'm now on client!
Of course, I realize asp.net results in html to the browser...sort of!!!

PLEASE show me an example of saving user-entered info within the
xmlDocument class? I don't want to save a "node" but the entire
document. See what I mean? Perhaps how to save the xmlDoc from within
the html javascript code?

Again, thanks for responding! I really appreciate it.

Kathy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 11 '05 #5
Kirk, hey I think I'm now starting to get this...thanks to you!

This is how I load my xmlDoc:

Dim xDoc As New XmlDocument()
Dim xTrans As New XslTransform()
xDoc.Load(Server.MapPath(varWI))
xTrans.Load(Server.MapPath("KB_Test.xsl"))
xTrans.Transform(xDoc, Nothing, Response.Output)

...not using an .net xml web control...does that matter?

In your example, it looks like we're loading the doc twice? once in the
first 2 lines, then again If(!IsPostBack)?

under the else lines:

this is how I would change the node.value of the input box
element...yes? is there any way to simply save the entire doc without
having to save each node.value that is changed? (probably not, would be
too simple!).

This helps a lot, thanks. Could you possibly give me a quick example of
the Onclick javascript within the html that would perform the above?

Kathy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 11 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by serge calderara | last post: by
2 posts views Thread by Graham Pengelly | last post: by
3 posts views Thread by BrianDH | last post: by
1 post views Thread by shapper | last post: by
reply views Thread by Saiars | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.