Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception throw if HTML element contains XMLNS attribute #2

Open
cmwoods opened this issue Apr 8, 2013 · 2 comments
Open

Exception throw if HTML element contains XMLNS attribute #2

cmwoods opened this issue Apr 8, 2013 · 2 comments

Comments

@cmwoods
Copy link

cmwoods commented Apr 8, 2013

I'm getting the following exception thrown when the HTML element contains the XMLNS attribute (in XHTML document):

Unhandled Exception: System.ArgumentException: The namespace declaration attribute has an incorrect 'namespaceURI': ''.
   at System.Xml.XmlDocument.AddAttrXmlName(String prefix, String localName, String namespaceURI, IXmlSchemaInfo schemaInfo)
   at System.Xml.XmlDocument.CreateAttribute(String prefix, String localName, String namespaceURI)
   at System.Xml.XmlElement.SetAttribute(String localName, String namespaceURI, String value)
   at HtmlParserSharp.XmlTreeBuilder.CreateHtmlElementSetAsRoot(HtmlAttributes attributes) in [...]\HtmlParserSharp\TreeBuilders\XmlTreeBuilder.cs:line 120
   at HtmlParserSharp.Core.TreeBuilder`1.AppendHtmlElementToDocumentAndPush(HtmlAttributes attributes) in [...]\HtmlParserSharp\Core\TreeBuilder.cs:line 5237
   at HtmlParserSharp.Core.TreeBuilder`1.StartTag(ElementName elementName, HtmlAttributes attributes, Boolean selfClosing) in [...]\HtmlParserSharp\Core\TreeBuilder.cs:line 2775
   at HtmlParserSharp.Core.Tokenizer.EmitCurrentTagToken(Boolean selfClosing, Int32 pos) in [...]\HtmlParserSharp\Core\Tokenizer.cs:line 1155
   at HtmlParserSharp.Core.Tokenizer.StateLoop(TokenizerState state, Char c, Int32 pos, Char[] buf, Boolean reconsume, TokenizerState returnState, Int32 endPos) in [...]\HtmlParserSharp\Core\Tokenizer.cs:line 2249
   at HtmlParserSharp.Core.Tokenizer.TokenizeBuffer(UTF16Buffer buffer) in [...]\HtmlParserSharp\Core\Tokenizer.cs:line 1382
   at HtmlParserSharp.SimpleHtmlParser.Tokenize(TextReader reader) in [...]\HtmlParserSharp\SimpleHtmlParser.cs:line 134
   at HtmlParserSharp.SimpleHtmlParser.Parse(TextReader reader) in [...]\HtmlParserSharp\SimpleHtmlParser.cs:line 63

It looks like the code is not particularly expecting XHTML input and therefore doesn't have a special case for the handling of this attribute.

@cmwoods
Copy link
Author

cmwoods commented Apr 9, 2013

Changed CreateHtmlElementSetAsRoot in XmlTreeBuilder.cs to have the following within the for loop (hack for error):

                string uri = attributes.GetURI(i);
                if (attributes.GetLocalName(i) == "xmlns" && string.IsNullOrWhiteSpace(uri))
                {
                    uri = "http://www.w3.org/2000/xmlns/";
                }
                rv.SetAttribute(attributes.GetLocalName(i), uri, attributes.GetValue(i));

I don't know if this is actually the correct thing to do or not but it at least gets around the issue.

@toothbrush7777777
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants