"Invalid Xml" with XmlTransform

G

GS

Hi!

I am getting an "Invalid Xml" exception when I try to load an xsl file
using XslTransform.Load(string url). The Xsl file is valid and works
fine if I just rename the file.

There are some postings with this problem, but none of them have a
solution as yet. If anyone has any ideas on how to resolve this, please
do post.

Thank you.
 
J

John Bailo

GS said:
Hi!

I am getting an "Invalid Xml" exception when I try to load an xsl file
using XslTransform.Load(string url). The Xsl file is valid and works
fine if I just rename the file.

There are some postings with this problem, but none of them have a
solution as yet. If anyone has any ideas on how to resolve this, please
do post.

Thank you.

http://msdn.microsoft.com/library/d...rfsystemxmlxslxsltransformclassloadtopic2.asp
Is this what you're doing?

using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;

public class Sample
{
private const String filename = "books.xml";
private const String stylesheet = "output.xsl";

public static void Main()
{
//Load the stylesheet.
XslTransform xslt = new XslTransform();
xslt.Load(stylesheet);

//Load the file to transform.
XPathDocument doc = new XPathDocument(filename);

//Create an XmlTextWriter which outputs to the console.
XmlTextWriter writer = new XmlTextWriter(Console.Out);

//Transform the file and send the output to the console.
xslt.Transform(doc, null, writer, null);
writer.Close();

}
}
 
G

GS

Yes, but it fails at ---

xslt.Load(stylesheet);

Also the xml and the xsl files are not as simple as in the example.
 
J

John Bailo

I've seen this happen where you may need to use special entity
characters to replace ampersands and other characters.

SO

<myxml>This & that</myxml>

becomes

<myxml>This &amp; that</myxml>
 
G

GS

I don't know what the problem was, but I re-installed IIS. It certainly
fixed the problem.
 

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

Top