470,815 Members | 1,335 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

"Invalid Xml" with XmlTransform

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.

Feb 17 '06 #1
7 2043
GS wrote:
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/de...loadtopic2.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();

}
}
Feb 18 '06 #2
GS
Yes, but it fails at ---

xslt.Load(stylesheet);

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

Feb 18 '06 #3

Are you using a try/catch block and can you see the exception?

GS wrote:
Yes, but it fails at ---

xslt.Load(stylesheet);

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

Feb 18 '06 #4

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>

GS wrote:
Yes, but it fails at ---

xslt.Load(stylesheet);

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

Feb 18 '06 #5
GS
I don't know what the problem was, but I re-installed IIS. It certainly
fixed the problem.

Feb 20 '06 #6
I had a likely problem
this part of code:

I am working with .NET and IIS6


Expand|Select|Wrap|Line Numbers
  1. XslTransform xslt = null;
  2. try
  3. {
  4. xslt = new XslTransform();
  5. xslt.Load(currentFile);    
  6. }
  7. catch(Exception Ex)
  8. {
  9. throw new Exception("XSLLoadError", currentFile, Ex.Message);
  10. }
  11. return xslt;
was working for everybody at work exept for me
when the debbuger reach the line

Expand|Select|Wrap|Line Numbers
  1. xslt.Load(currentFile);
it was throwing an exception "Invalid xml"

I was testing the xslt, and it was fine.
I test the xslt with an altern program to transform and xml by using a xslt
and it works fine
so that, the problem was not in the xslt file

I have restarted the server several times, deleted temporal files but the same for one specific XSLT the Exception is thrown again. :confused:

I will try your solution about re-install the IIS. :cool:

for now, after being debbuging, I had the idea to rename the XSLT
and in someway, the

Expand|Select|Wrap|Line Numbers
  1. xslt.Load(currentFile);
works with my XSLT file :D

my old name was: FIN.IN.AR.Carrier.xslt
my new name: FIN.IN.AR.Carriers.xslt

As you can see I cannot find a factible reason why was happing this issue
any idea about the real reason because

after it works I return back to the filename that was wich one I had had the problem

and the problem appeared again :confused:

regards
Mar 2 '06 #7
Me again,

About this problem.

I delete the .NET temp files
from:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Tempo rary ASP.NET Files

besides I remove temp files by using the menu
Tools > Internet Options > delete Files > Delete All Online Content > OK

I thought that that it could fix my problem with the Invalid Xml, maybe it is a problem,
but that does not work, :mad:

I think there are a problem with the memory
with the cache memory or somethig about it :confused:

finally

I create a new website with another diferent name

I install my application in that new Site

and the problem has gone :p


I think that In some way, IIS or the Net Framework itselft was storing a reference to a wrong file

so that, when you re-install the ISS the reference was clearer
and when I create a new Site, the reference was a new one

when I was using the same site, I think it was using the same reference where the error was

If someone had a better answer for this issue
I will be waiting for it

Thanks
Mar 2 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Tjerk Wolterink | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.