[英]How might I use the W3C Markup Validator API in my .NET application?
I found that there's an API for the W3C Markup Validator .我发现W3C Markup Validator 有一个 API 。
I had earlier asked: Is there a .NET library for the W3C Markup Validator API?我之前问过: 是否有用于 W3C 标记验证器 API 的 .NET 库?
This API is SOAP based.
此 API 是基于 SOAP 的。 If you want to use it in a .net application you can just add the web reference and code against it.
如果您想在 .net 应用程序中使用它,您只需添加 web 参考和代码即可。 Seems simple enough as it's basically a one-method API...
看起来很简单,因为它基本上是一种方法 API ...
So, I tried to "Add Service Reference" at address http://validator.w3.org/check
.因此,我尝试在地址
http://validator.w3.org/check
处“添加服务参考”。
First the dialog displays:首先对话框显示:
Please wait for service information to be downloaded...
请等待下载服务信息...
Then:然后:
An error... occurred while attempting to find services at ' http://validator.w3.org/check '
尝试在“ http://validator.w3.org/check ”中查找服务时发生错误...
Visual Studio Add Service Reference Dialog http://img17.imageshack.us/img17/719/addservicereference.gif Visual Studio 添加服务参考对话框 http://img17.imageshack.us/img17/719/addservicereference.gif
Error details:错误详情:
The HTML document does not contain Web service discovery information.
HTML 文档不包含 Web 服务发现信息。 Metadata contains a reference that cannot be resolved: ' http://validator.w3.org/check '.
元数据包含无法解析的引用:“ http://validator.w3.org/check ”。 The content type text/html;
内容类型 text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8).
响应消息的 charset=utf-8 与绑定的内容类型不匹配 (application/soap+xml; charset=utf-8)。 If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly.
如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。 The first 1024 bytes of the response were:
响应的前 1024 个字节是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>
Validation Results - W3C Markup Validator</title>
<link rel="icon" href="data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%02%00%00%00%90%91h6%00%00%00%19IDAT(%91c%BCd%AB%C2%40%0A%60%22I%F5%A8%86Q%0DCJ%03%00%DE%B5%01S%07%88%8FG%00%00%00%00IEND%AEB%60%82" type="image/png" />
<link rev="made" href="mailto:www-validator@w3.org" />
<link rev="start" href="./" title="Home Page" />
<style type="text/css" media="all">@import "./style/base.css";
@import "./style/results.css";</style>
<meta name="keywords" content="HTML, HyperText Markup Language, Validation,
W3C Markup Validation Service" />
<meta name="description" content="W3C's easy-to-use
H
If the service is defined in the current solution, try building the solution and adding the service reference again.
如果在当前解决方案中定义了服务,请尝试构建解决方案并再次添加服务引用。
How can I use the W3C Markup Validator API in my .NET application?如何在我的 .NET 应用程序中使用 W3C 标记验证器 API?
The W3C Service is no standard SOAP Service! W3C 服务不是标准的 SOAP 服务! It can give a SOAP formatted response but to call it's a sinple REST URL based Service http://validator.w3.org/check?uri=YourURLToProof&charset=utf-8&output=soap12
It can give a SOAP formatted response but to call it's a sinple REST URL based Service http://validator.w3.org/check?uri=YourURLToProof&charset=utf-8&output=soap12
In order for a Web Reference to work, I think it needs the owner of the service to have published a WSDL file for.Net to read and create local objects with.为了让 Web 参考工作,我认为它需要服务的所有者发布一个 WSDL 文件用于 .Net 来读取和创建本地对象。 You then call these local objects in your project, and they get populated with Data from the other end of the service using SOAP.
然后,您在项目中调用这些本地对象,并使用 SOAP 使用来自服务另一端的数据填充它们。
I've been looking for a WSDL file that describes the W3C's validation SOAP on their site somewhere, but no luck so far.我一直在寻找描述 W3C 验证 SOAP 的 WSDL 文件,但到目前为止还没有运气。 Which is odd given the W3C manage the WSDL protocol.
鉴于 W3C 管理 WSDL 协议,这很奇怪。 You'd really expect them to use it!
你真的希望他们使用它!
If anyone knows:如果有人知道:
Then please let me know...那么请告诉我...
Failing that - the W3C have put a link to a C# library on their site ( http://validator.w3.org/docs/api.html#libs ), which is easy enough to download and build.如果做不到这一点 - W3C 在他们的网站( http://validator.w3.org/docs/api.html#libs )上放置了指向 C# 库的链接,该库很容易下载和构建。 But that uses LINQ to build an object based on the SOAP returned by the W3C - which seems a bit heavy for my purposes... It's a useful starting point if nothing else tho.
但这使用 LINQ 来构建基于 W3C 返回的 SOAP 的 object - 这对于我的目的来说似乎有点沉重......如果没有别的,这是一个有用的起点。
A SOAP Web Service must have a WSDL. SOAP Web 服务必须具有 WSDL。 I have seen some mentions on the W3C site of a SOAP API, but the location of the API or the WSDL to it is not apparent.
I have seen some mentions on the W3C site of a SOAP API, but the location of the API or the WSDL to it is not apparent.
Poking around and searching with Bing, I found the following: http://www.w3.org/Search/Mail/Public/search?type-index=www-validator&index-type=t&keywords=wsdl&search=Search用必应四处寻找和搜索,我发现了以下内容: http://www.w3.org/Search/Mail/Public/search?type-index=www-validator&index-type=t&keywords=wsdl&search=Search
Good luck.祝你好运。 It seems they've done this a bit backwards, with the web service being an afterthought from people who don't quite get the concept of a WSDL.
似乎他们在这方面做得有点倒退,web 服务是那些不太了解 WSDL 概念的人的事后想法。
You can actually download and install the validator on to your own site from https://github.com/validator/validator您实际上可以从https://github.com/validator/validator下载验证器并将其安装到您自己的站点上
Some useful notes from the about page关于页面的一些有用说明
I made a quick c# validator method from calling: https://validator.w3.org/nu/?doc=http://www.example.com&out=json我通过调用创建了一个快速的 c# 验证器方法: https://validator.w3.org/nu/?doc=http://www.example.com&out=json
like so:像这样:
using Newtonsoft.Json;
using System.Net;
using System.Net.Http;
private void ValidateFromW3Org(string url)
{
HttpClientHandler clientHandler = new HttpClientHandler();
HttpClient client = new HttpClient(clientHandler);
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent",
"Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
string validator = string.Format(
"http://validator.w3.org/nu/?doc={0}&out=json", url);
string response = client.GetStringAsync(url).Result;
PageValidationResult pageResults = JsonConvert.DeserializeObject<
PageValidationResult>(response);
IList<ValidationResult> results = pageResults.Messages;
foreach(ValidationResult result in results)
{
Console.WriteLine("{0}:{1} line: {2} - {3}", result.Type,
result.SubType, result.LastLine, result.Message);
}
}
public class ValidationResult
{
public string Type { get; set; }
public string SubType { get; set; }
public int LastLine { get; set; }
public int FirstColumn { get; set; }
public int LastColumn { get; set; }
public string Message { get; set; }
public string Extract { get; set; }
public int HiliteStart { get; set; }
public int HiliteLength { get; set; }
}
public class PageValidationResult
{
public string Url { get; set; }
public IList<ValidationResult> Messages { get; set; }
}
Please note this is a just a sample.请注意,这只是一个示例。 You wouldn't want to re-use HttpClient in a method that way.
您不想以这种方式重用 HttpClient 。 This also uses third party Newtonsoft.Json to parse json result.
这也使用第三方 Newtonsoft.Json 来解析 json 结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.