XML and XSL translation

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hi,

I am trying to do an XML translation. I have not done much with XML apart
from generating a few RSS feeds or saving from datasets.

I have found numerous example on the net about it, all of them very similar.
However, when I use them, they go into response.output rather than a label
or literal. I am trying to drop the output into a literal.

Here is the code I have...


try
{
XPathDocument _SourceXml = new
XPathDocument("http://www.nationalgrid.com/uk/Interconnectors/France/Results/Weekend+Auctions/rss.htm");

// Load the XSL stylesheet
XslTransform _Transform = new XslTransform();
_Transform.Load("http://www.nationalgrid.com/static/xsl/ngcomrss.xsl");

// Write output to the screen.

//TextReader tr = new TextReader();
//StreamReader sr = new StreamReader();
_Transform.Transform(_SourceXml, null, Response.Output);
//_Transform.Transform(_SourceXml, null, tr);

//XMLDisplay.Text = tr.ReadToEnd();

}
catch(Exception ex)
{
Response.Write(ex.Message);
}


As you can see, I have tried setting up a stream to drop the output into,
but the compiler is complaining at the "new" word.

As it is, it drops the text at the top of the page. I want to control where
it sits, so I want to drop it in a literal instead. How can I do that?

Thanks.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Hi,

I am trying to do an XML translation. I have not done much with XML apart
from generating a few RSS feeds or saving from datasets.

I have found numerous example on the net about it, all of them very similar.
However, when I use them, they go into response.output rather than a label
or literal. I am trying to drop the output into a literal.

I can suggest you to use the StringWriter

StringWriter sw = new StringWriter();
_Transform.Transform(_SourceXml, null, sw);
string result = sw.ToString();
sw.Close();

Response.Write(result);
 
Cool, that works... thank you.

However, I do have a slight problem appearing.

'System.Xml.Xsl.XslTransform.Transform(System.Xml.XPath.IXPathNavigable,
System.Xml.Xsl.XsltArgumentList, System.IO.TextWriter)' is obsolete: 'You
should pass XmlResolver to Transform() method'

What do I need to do to stop this? I don't know what the XmlResolver is.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Cool, that works... thank you.

However, I do have a slight problem appearing.

'System.Xml.Xsl.XslTransform.Transform(System.Xml.XPath.IXPathNavigable,
System.Xml.Xsl.XsltArgumentList, System.IO.TextWriter)' is obsolete: 'You
should pass XmlResolver to Transform() method'

What do I need to do to stop this? I don't know what the XmlResolver is.


The XslTransform class has been replaced in .NET 2 with a new XSLT 1.0
implementation - the XslCompiledTransform class. XslCompiledTransform
compiles XSLT stylesheets to Microsoft Intermediate Language (MSIL)
methods and then executes them. Execution time of the new processor is
on average 4 times better than XslTransform and matches the speed of
MSXML, the native XML processor.

You should replace

XslTransform _Transform = new XslTransform();

by this line

XslCompiledTransform _Transform = new XslCompiledTransform();

to skip the "obsolete" message.

You may find also interesting the following article
Migrating From the XslTransform Class
http://msdn2.microsoft.com/en-us/library/66f54faw.aspx
 
Back
Top