473,725 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting an XMLWriter from an XslCompiledTran sform.Transform call

Hi all,

I'm having a real problem with getting an XMLWriter as a result of an
xsl tranform I'm attempting.

My code is:

private void btnPerformTrans form_Click(obje ct sender, EventArgs e) {
// Load the style sheet.
XslCompiledTran sform xslt = new XslCompiledTran sform();
XmlWriter xmlWriter = new XmlTextWriter(n ew StringWriter()) ;

xslt.Load("Flig htsAvail.xsl");

xslt.Transform( "testXMLIn.xml" , xmlWriter);

Console.Out.Wri te("");
}

This code is returning the following exception:

Execution of the 'document()' function was prohibited. Use the
XsltSettings.En ableDocumentFun ction property to enable it.

I've tried numerous alternatives to get this to work and I'm frustrated
because I know its going to be really simple.

One thing I'd point out though, is that it doesn't really matter what
object form the output of the transform comes as - as long as I can then
load it into an XMLDocument instance without having to write the output
of the transform to a file first.

I've been trying all sorts of things with memory streams and what not,
but I keep coming up against exceptions. As you can maybe tell, I don't
do IO stuff very often.

If anyone has any code that can get me an xmlwriter or something similar
containing the results of an xsl transform I would be really grateful.

Many thanks in advance

Kindest Regards

Simon
Dec 8 '06 #1
2 8828
OK - you have 2 things going on. The main one *isn't* an IO problem.

The first is that the XslCompiledTran sform (as the error suggests)
*disables* certain functions by default; so if your xsl *uses* functions
like document(), then to get this to behave like you want you need to do
what the exception says: when you call Load, you must use the overload that
accepts an options object, to which you should enable this mode.

However, related to getting the writer... at the moment you are transforming
into an xmlwriter that is going to write to a stringwriter, which *you don't
have a reference to*, so you can't actually get the results.

You need to do something like
StringWriter sw = new StringWriter();
XmlWriter xmlWriter = new XmlTextWriter(s w);
xslt.Transform( path, xmlWriter);
string xml = sw.ToString();

(note if you lose trailing data you may need to Flush(), Close() or
Dispose() the xmlWriter before calling sw.ToString()).

Marc
Dec 8 '06 #2
Marc Gravell wrote:
OK - you have 2 things going on. The main one *isn't* an IO problem.

The first is that the XslCompiledTran sform (as the error suggests)
*disables* certain functions by default; so if your xsl *uses* functions
like document(), then to get this to behave like you want you need to do
what the exception says: when you call Load, you must use the overload that
accepts an options object, to which you should enable this mode.

However, related to getting the writer... at the moment you are transforming
into an xmlwriter that is going to write to a stringwriter, which *you don't
have a reference to*, so you can't actually get the results.

You need to do something like
StringWriter sw = new StringWriter();
XmlWriter xmlWriter = new XmlTextWriter(s w);
xslt.Transform( path, xmlWriter);
string xml = sw.ToString();

(note if you lose trailing data you may need to Flush(), Close() or
Dispose() the xmlWriter before calling sw.ToString()).

Marc

Hi Marc,

I've got it working now.

Huge thank you to you for the advice

Kindest Regards

Simon
Dec 8 '06 #3

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

Similar topics

0
993
by: Sohan Kamat | last post by:
Hi, We are using XSLCompiledTransform.Transform for Transforming XML to a text file. One of the XML tags has value <Address>Mahin & Mahin</Address> And in the XSL we have <xsl:value of select="Address"/> to select the value of the that node The o/p we are getting is "Mahin & Mahin", but we want "Mahin & Mahin" as output. We dont want to use disable output sequence attribute in XSL.
4
1872
by: benben | last post by:
I have the following code snippet: class converter { // ... public: virtual polar_point convert_to_polar(const point&) = 0; }; void f(const std::vector<point>& points, converter& cvt)
12
10112
by: InvalidLastName | last post by:
We have been used XslTransform. .NET 1.1, for transform XML document, Dataset with xsl to HTML. Some of these html contents contain javascript and links. For example: // javascript if (a &gt; b) ..... // xsl contents abc.aspx?p1=v1&amp;p2=<xsl:value-of select="$v2" />
5
8641
by: Kevin Burton | last post by:
I am trying an XSLT transformation using the XslCompiledTransform class. I get an exception when I call the Transform method. It seems to point to these two lines: <xsl:namespace name="{$schemaPrefix}" select="$schemaNamespace"/> <xsl:namespace name="{$prefix}" select="$targetNamespace"/> The exception looks like: System.Xml.Xsl.XslTransformException: 'select' is not a recognized extension
2
3393
by: Simon Harvey | last post by:
Hi all, I'm having a real problem with getting an XMLWriter as a result of an xsl tranform I'm attempting. My code is: private void btnPerformTransform_Click(object sender, EventArgs e) { // Load the style sheet. XslCompiledTransform xslt = new XslCompiledTransform();
1
1661
by: Mark | last post by:
I'm getting the error "The URI scheme is too long." in the code below. What is URI in this context? The XSL or the XML being transformed? Thanks! -Mark StringBuilder sb = new StringBuilder(); //Create the XslCompiledTransform and Load it with the xsltDocument XslCompiledTransform xslCompiledTransform = new XslCompiledTransform();
3
2360
by: wolverine | last post by:
Hi, I am injecting a javascript code into html pages and attaching some dom events to some elements via attachEvent (IE only). I just want to know that is there any chance by which my event handler not getting executed ? ie, is there some means for the web developer to prevent any further handler getting executed for the same event on the same element ? To be more clear, assume the web developer has attached function "f1()" on onclick...
5
2857
by: =?Utf-8?B?Um9iZXJ0?= | last post by:
Hello all, I have an XmlException being thrown trying to use XslCompiledTransform while using the google api. My suspicion is there is some html decoding happening that I want to prevent... something like this being changed into this
4
1421
by: jinendrashankar | last post by:
Hi In my Code i am creating 2 object of my class and in assigentment operator passing arugement by reference. In output of my code i am getting to 2 Constructor call which right but there is 3 Distructor call which i am not able to understand why 3 Distructor call #include<iostream.h> class A
0
8886
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8751
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9108
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8093
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6010
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4781
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3218
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2155
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.