在.Net Standard 2.0中使用XmlReader时,未声明'http://www.w3.org/XML/1998/namespace:lang'属性 [英] The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not declared problem when using XmlReader in .Net Standard 2.0

查看:152
本文介绍了在.Net Standard 2.0中使用XmlReader时,未声明'http://www.w3.org/XML/1998/namespace:lang'属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用某些阅读器设置阅读XmlReader中的HTML字符时遇到问题。



项目详情:

.Net Standard 2.0目标项目



问题详情:

创建时抛出异常消息XmlReader,其设置符合代码段。

" System.Xml.Schema.XmlSchemaValidationException

  HResult = 0x80131941

 消息=未声明'http://www.w3.org/XML/1998/namespace:lang'属性。"
$


行内异常抛出:   XmlReader阅读器
= XmlReader.Create(新的StringReader(html),设置);





代码片段:


 

FileStream stream = new FileStream(" xhtml1-transitional.xsd" ;,FileMode.Open,FileAccess.ReadWrite);
XmlSchema schema = XmlSchema.Read(stream,new ValidationEventHandler(OnValidation));
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(schema);
string html ="< html xmlns = \" http://www.w3.org/1999/xhtml\">< head>< title>< / title> < /头><主体>< p为H.你好< / p>< / BODY>< / HTML>英寸;

的XmlReader读取器的 = XmlReader.Create(新StringReader(HTML),设置);


的XmlDocument XMLDOCUMENT =新的XmlDocument ();
xmlDocument.Load(读者);
reader.Close();


对于相同的代码,WindowsForms应用程序中不会引发提到的异常。 .Net Standard 2.0有什么限制吗?或者是否有其他方法可以在.Net Standard 2.0中实现我的要求?

解决方案

嗨  Mohanaselvam,


感谢您在此发帖。


对于您的问题,您如何测试代码?我使用您提供的代码创建一个.net标准类库,并在.net Core项目中调用。由于我没有OnValidation,我会评论一些代码。效果很好。


我不认为这是.Net Standard 2.0的限制。


根据我的搜索,可能有许多DTD和XSD来自W3C,他们遇到的问题是许多人试图从他们的服务器,导致他们被请求淹没 - 数百万和数百万。所以他们
开始阻止"过度"请求。


有关详细信息,请参阅StackOverFlow中的主题。


https://stackoverflow.com/questions/6117627/the-http-www-w3-org- xml-1998-namespacelang-attribute-is-not-declared


最好的问候,


Wendy


I am facing a problem to read HTML string in XmlReader with some reader settings.

Project details :
.Net Standard 2.0 target project

Issue details:
Below exception message thrown when creating XmlReader with settings as per the code snippet.
"System.Xml.Schema.XmlSchemaValidationException
  HResult=0x80131941
  Message=The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not declared."

Exception thrown in line : XmlReader reader = XmlReader.Create(new StringReader(html), settings);


Code snippet:

FileStream stream = new FileStream("xhtml1-transitional.xsd", FileMode.Open, FileAccess.ReadWrite); XmlSchema schema = XmlSchema.Read(stream, new ValidationEventHandler(OnValidation)); XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.Schemas.Add(schema); string html = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title></head><body><p>hello</p></body></html>";

XmlReader reader = XmlReader.Create(new StringReader(html), settings);

XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(reader); reader.Close();

The mentioned exception doesn't throws in WindowsForms application for the same code. Is there any limitation for .Net Standard 2.0 ? Or Is any other approach to achieve my requirement in .Net Standard 2.0?

解决方案

Hi Mohanaselvam,

Thank you for posting here.

For your question, how do you test your code? I create a .net standard class library with the code you provided and invoke in .net Core project. Since I do not have OnValidation, I comment some code. It works well.

I do not think it is the limitation for .Net Standard 2.0.

Based on my search, maybe there are many of the DTDs and XSDs originated from the W3C, they have the problem that many people try to resolve them from their servers, resulting in their being inundated with requests - millions and millions of them. So they started blocking "excessive" requests.

For more details, please refer to the thread in StackOverFlow.

https://stackoverflow.com/questions/6117627/the-http-www-w3-org-xml-1998-namespacelang-attribute-is-not-declared

Best Regards,

Wendy


这篇关于在.Net Standard 2.0中使用XmlReader时,未声明'http://www.w3.org/XML/1998/namespace:lang'属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆