473,395 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

XML transformation

In my application I am transforming the XML based on XSL. Then I've to show
the transformed content in the browser. (.net -C#)
For that I am dumping the transformed content in a file, then i am reading
the content from that file and showing in the browser.

Is there any way I can avoid writing in the file.
Oct 25 '06 #1
4 1577
Is the transform at the client or the web-server?

If the web-server, then you should be able to pass the response-stream
(or a writer in a suitable encoding) directly to the
XslCompiledTransform, so it can write directly to the response stream.

If the client, then if you are happy to use IEs choice of XSL you could
use the trick of embedding the transform into the xml and let IE worry
about it. Otherwise you could perhaps transform into to a StringWriter,
and then write the .ToString() into the browser's HTML.

Any use?

Marc

Oct 25 '06 #2
Well the application is a stand-alone tyep. It will show the transformed
content in the browser embedded in the window-Form.
this is thing which I'm doing:

XPathDocument myXPathDocument = new
XPathDocument(XMLfileName);
XslCompiledTransform myXslTransform = new
XslCompiledTransform();
writer = new XmlTextWriter(outputFileName, null);
myXslTransform.Load(xslFileName);
myXslTransform.Transform(myXPathDocument,null, writer);
writer.Close();
stream = new StreamReader(outputFileName);
string output = stream.ReadToEnd().ToString();
the problem is that it takes around 5 seconds in the very first time to show
the content after that it does the same activity within 1 second or so.

so i've to reduce this time thing. So What i see that since IO operation are
time consuming operation and if we are able to remove file writing and
reading we can save some time.
So any idea in that side??

"Marc Gravell" wrote:
Is the transform at the client or the web-server?

If the web-server, then you should be able to pass the response-stream
(or a writer in a suitable encoding) directly to the
XslCompiledTransform, so it can write directly to the response stream.

If the client, then if you are happy to use IEs choice of XSL you could
use the trick of embedding the transform into the xml and let IE worry
about it. Otherwise you could perhaps transform into to a StringWriter,
and then write the .ToString() into the browser's HTML.

Any use?

Marc

Oct 25 '06 #3
Personally, I doubt that disk IO is the problem, unless you are writing
over the network.
5 seconds in the very first time to show
the content after that it does the same activity within 1 second or so
To clarify; are you re-running the code you posted when you do this? Or
are you re-displaying the existing (html) file? This 5 seconds could be
a number of things:
* "Fusion" loading the necessary assemblies (look to see what
assemblies are loading /when [in the output window of VS]); you could
try and force them load earlier to stop this looking slow
* Compiling the transform; although I'm not entirely sure about this
because from your code you don't actually seem to hold onto the
transform... so not entirely sure why you would bother compiling it ;-p
Generally I would expect this single XslCompiledTransform to be re-used
in successive calls
* Applying the transform; it isn't clear whether you are re-running it
each time; if not, it could just be a poorly written transform. The
typical example is grouping data; if you use axes such as ancestor:: or
preceeding-sibling:: to group data, you will get poor performance;
Munchean grouping is the way to do this...

Have you tried swapping the XmlTextWriter for a StringWriter? I suspect
this would be a very simple test, and would rule out the IO. You can
probably use the following overload, with arguments=null, since
StringWriter is a TextWriter. Note this /probably/ (haven't tested)
also avoids the runtime having to encode [writing] / decode [reading]
to / from bytes which you would have with a MemoryStream... as you
simply call .ToString() to get the HTML and set this (as a string) into
the browser control. Hopefully the HTML isn't insanely big.
Transform(System.Xml.XPath.IXPathNavigable input,
System.Xml.Xsl.XsltArgumentList arguments, System.IO.TextWriter
results)

But again, I strongly suspect that IO isn't the issue, unless you are
dealing with very large xml sets, in which case I would *actively
recommend* using the (local) file-system as the buffer, as it avoids
filling up system memory and having to keep block-copying the arrays as
it gets better (which is what would happen behind the scenes with a
MemoryStream).

Do you happen to have a short example (with the necessary xml and xslt)
that demonstrates this bottleneck? They may be a bit long for ideal
usenet usage, but if you e-mail them or post them somewhere I could
have a look-see...

Marc

Oct 25 '06 #4
Try this:

// ensure:
using System.Text;
using System.IO;

// This is your code:
XPathDocument myXPathDocument = new XPathDocument(XMLfileName);
XslCompiledTransform myXslTransform = new XslCompiledTransform();
// Prepare an output stream based on a System.Text.StringBuilder():
StringBuilder sbResult = new StringBuilder();
StringWriter sResult = new StringWriter(sbResult);
XmlTextWriter sXML = new XmlTextWriter(sResult);
// Load the XSL, your code:
myXslTransform.Load(xslFileName);
// Perform transform, your code modified to use new stream:
myXslTransform.Transform(myXPathDocument,null, sXML);
// Make sure the stream's written everything to the underlying buffer:
sXML.Flush();
// Retrieve string:
string output = sbResult.ToString();
If you have a string input instead of a file (i.e. -- if you're writing
your string to a file because you don't know how to create an
XPathDocument based on a stream or a string), you can do something
similar with a StreamReader or StringReader/XmlTextReader.

If you're still having performance issues, you need to perform the
stems that Marc suggested, like looking at: 1) the size of the XML, 2)
the size of the XSL, 3) the quality of the XSL code. You should be able
to transform a 1 MB XML with an XSL file around 5k that's well written
without any noticeable delay.
Stephan


callavin wrote:
Well the application is a stand-alone tyep. It will show the transformed
content in the browser embedded in the window-Form.
this is thing which I'm doing:

XPathDocument myXPathDocument = new
XPathDocument(XMLfileName);
XslCompiledTransform myXslTransform = new
XslCompiledTransform();
writer = new XmlTextWriter(outputFileName, null);
myXslTransform.Load(xslFileName);
myXslTransform.Transform(myXPathDocument,null, writer);
writer.Close();
stream = new StreamReader(outputFileName);
string output = stream.ReadToEnd().ToString();
the problem is that it takes around 5 seconds in the very first time to show
the content after that it does the same activity within 1 second or so.

so i've to reduce this time thing. So What i see that since IO operation are
time consuming operation and if we are able to remove file writing and
reading we can save some time.
So any idea in that side??

"Marc Gravell" wrote:
Is the transform at the client or the web-server?

If the web-server, then you should be able to pass the response-stream
(or a writer in a suitable encoding) directly to the
XslCompiledTransform, so it can write directly to the response stream.

If the client, then if you are happy to use IEs choice of XSL you could
use the trick of embedding the transform into the xml and let IE worry
about it. Otherwise you could perhaps transform into to a StringWriter,
and then write the .ToString() into the browser's HTML.

Any use?

Marc
Oct 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
3
by: pradeep gummi | last post by:
I have an XML FILE that is to be converted to Plain Text using an XSL file. Since I just want plain text, I do not want to set any root element during transformation.And if I do not any root...
4
by: Kevin Dean | last post by:
I'm trying to create an XSL transformation that will strip out development-specific attributes from deployment descriptors and other XML files. I have already successfully done so with web.xml but...
7
by: CK | last post by:
Hello, I have the 60 MB XML string and I am coding a program in Visual Basic to run a XSL transformation on it. Currently, I'm using the Microsoft standard MSXML 2.0 to create a DOM document, load...
8
by: Will | last post by:
I was thrust into XML about 2 weeks ago and don't know much yet. From another department in the corp I am receiving an XML file which concatenates nodes all on one line i.e....
4
by: Mike Conmackie | last post by:
Hi Folks, I've probably omitted something very basic but I have no idea what it might be. The results of my transformation _should_ be an xml file but all I get is the xml declaration...
6
by: Jain, Pranay Kumar | last post by:
Hi All, We have created a simple application that takes a dataset and generates the data in Excel schema format. It uses an xslt file to do the transformation for excel 2002 and so on. We are...
2
by: TomekR | last post by:
Hello ! I was developing xslt sheet lately and - experimenting - I made mistake resulting in that, the effect of the transformation is not well-formed xml document. I made these tests using...
2
by: HendrikLeder | last post by:
Hello everybody :-) Next year I`ll write my diploma in computer science for business (It`s a degree in Germany) and I`ve some questions about the topic. The diploma will handle about refactoring...
1
by: newbie | last post by:
This is probably a too general question, thanks for any feedback in advance. I am trying to write a class to do transformation on a data set. I want to make it easy to maintain in the long-run...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.