XML and XSL translation

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
 
G

Guest

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);
 
D

David

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
 
G

Guest

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
 
G

Guest

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top