简体   繁体   中英

Name cannot begin with the '=' character hexadecimal value 0x3d when use xslt

I have some html. I try to clean it with library: http://sourceforge.net/projects/tidynet/

Here is my code:

//clean up html
            Tidy tidy = new Tidy();

            tidy.Options.DocType = DocType.Omit;
            tidy.Options.DropFontTags = true;
            tidy.Options.LogicalEmphasis = true;
            tidy.Options.Xhtml = true;
            tidy.Options.XmlOut = true;
            tidy.Options.MakeClean = true;
            tidy.Options.TidyMark = false;
            tidy.Options.CharEncoding = CharEncoding.UTF8;


            /* Declare the parameters that is needed */
            TidyMessageCollection tmc = new TidyMessageCollection();
            MemoryStream input = new MemoryStream();
            MemoryStream output = new MemoryStream();

            byte[] byteArray = Encoding.UTF8.GetBytes(report);
            input.Write(byteArray, 0, byteArray.Length);
            input.Position = 0;
            tidy.Parse(input, output, tmc);

            string cleanHtml = Encoding.UTF8.GetString(output.ToArray());

then I try to use xslt:

try
            {
                StringBuilder res = new StringBuilder();
                XslCompiledTransform xslt = new XslCompiledTransform();
                xslt.Load(XmlReader.Create(new StringReader(stylesheet.Content)));
                xslt.Transform(StringExtensions.ToXmlReader(cleanHtml), null, new StringWriter(res));
                var resultReport = res.ToString();
            }
            catch (Exception e)
            {

            }

and I get an exeption:

The '=' character, hexadecimal value 0x3D, cannot be included in a name

Update How can I automaticaly clean name from '='?

HTML is not XML (unless it's XHTML). Trying to apply an XSLT to a generic HTML document is almost certainly going to give you issues. You'll have to find a different way to do whatever transformation it is that you're looking for.

If you want to process the HTML programmatically, then I would suggest the HTML Agility Pack .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM