如何将 HTML 转换为 XHTML?

发布于 2024-07-06 22:23:38 字数 1832 浏览 10 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

一直在等你来 2024-07-13 22:23:38

使用 HTML Tidy 将 HTML 转换为 XML

< a href="http://tidy.sourceforge.net/#binaries" rel="nofollow noreferrer">可下载的二进制文件

JRoppert,根据您的需要,我想您可能想看看在来源

c:\temp>tidy -help
tidy [option...] [file...] [option...] [file...]
Utility to clean up and pretty print HTML/XHTML/XML
see http://tidy.sourceforge.net/

Options for HTML Tidy for Windows released on 14 February 2006:

File manipulation
-----------------
 -output <file>, -o  write output to the specified <file>
 <file>
 -config <file>      set configuration options from the specified <file>
 -file <file>, -f    write errors to the specified <file>
 <file>
 -modify, -m         modify the original input files

Processing directives
---------------------
 -indent, -i         indent element content
 -wrap <column>, -w  wrap text at the specified <column>. 0 is assumed if
 <column>            <column> is missing. When this option is omitted, the
                     default of the configuration option "wrap" applies.
 -upper, -u          force tags to upper case
 -clean, -c          replace FONT, NOBR and CENTER tags by CSS
 -bare, -b           strip out smart quotes and em dashes, etc.
 -numeric, -n        output numeric rather than named entities
 -errors, -e         only show errors
 -quiet, -q          suppress nonessential output
 -omit               omit optional end tags
 -xml                specify the input is well formed XML
 -asxml, -asxhtml    convert HTML to well formed XHTML
 -ashtml             force XHTML to well formed HTML
 -access <level>     do additional accessibility checks (<level> = 0, 1, 2, 3).
                     0 is assumed if <level> is missing.

Character encodings
-------------------
 -raw                output values above 127 without conversion to entities
 -ascii              use ISO-8859-1 for input, US-ASCII for output
 -latin0             use ISO-8859-15 for input, US-ASCII for output
 -latin1             use ISO-8859-1 for both input and output
 -iso2022            use ISO-2022 for both input and output
 -utf8               use UTF-8 for both input and output
 -mac                use MacRoman for input, US-ASCII for output
 -win1252            use Windows-1252 for input, US-ASCII for output
 -ibm858             use IBM-858 (CP850+Euro) for input, US-ASCII for output
 -utf16le            use UTF-16LE for both input and output
 -utf16be            use UTF-16BE for both input and output
 -utf16              use UTF-16 for both input and output
 -big5               use Big5 for both input and output
 -shiftjis           use Shift_JIS for both input and output
 -language <lang>    set the two-letter language code <lang> (for future use)

Miscellaneous
-------------
 -version, -v        show the version of Tidy
 -help, -h, -?       list the command line options
 -xml-help           list the command line options in XML format
 -help-config        list all configuration options
 -xml-config         list all configuration options in XML format
 -show-config        list the current configuration settings

Use --blah blarg for any configuration option "blah" with argument "blarg"

Input/Output default to stdin/stdout respectively
Single letter options apart from -f may be combined
as in:  tidy -f errs.txt -imu foo.html
For further info on HTML see http://www.w3.org/MarkUp

Convert from HTML to XML with HTML Tidy

Downloadable Binaries

JRoppert, For your need, i guess you might want to look at the Sources

c:\temp>tidy -help
tidy [option...] [file...] [option...] [file...]
Utility to clean up and pretty print HTML/XHTML/XML
see http://tidy.sourceforge.net/

Options for HTML Tidy for Windows released on 14 February 2006:

File manipulation
-----------------
 -output <file>, -o  write output to the specified <file>
 <file>
 -config <file>      set configuration options from the specified <file>
 -file <file>, -f    write errors to the specified <file>
 <file>
 -modify, -m         modify the original input files

Processing directives
---------------------
 -indent, -i         indent element content
 -wrap <column>, -w  wrap text at the specified <column>. 0 is assumed if
 <column>            <column> is missing. When this option is omitted, the
                     default of the configuration option "wrap" applies.
 -upper, -u          force tags to upper case
 -clean, -c          replace FONT, NOBR and CENTER tags by CSS
 -bare, -b           strip out smart quotes and em dashes, etc.
 -numeric, -n        output numeric rather than named entities
 -errors, -e         only show errors
 -quiet, -q          suppress nonessential output
 -omit               omit optional end tags
 -xml                specify the input is well formed XML
 -asxml, -asxhtml    convert HTML to well formed XHTML
 -ashtml             force XHTML to well formed HTML
 -access <level>     do additional accessibility checks (<level> = 0, 1, 2, 3).
                     0 is assumed if <level> is missing.

Character encodings
-------------------
 -raw                output values above 127 without conversion to entities
 -ascii              use ISO-8859-1 for input, US-ASCII for output
 -latin0             use ISO-8859-15 for input, US-ASCII for output
 -latin1             use ISO-8859-1 for both input and output
 -iso2022            use ISO-2022 for both input and output
 -utf8               use UTF-8 for both input and output
 -mac                use MacRoman for input, US-ASCII for output
 -win1252            use Windows-1252 for input, US-ASCII for output
 -ibm858             use IBM-858 (CP850+Euro) for input, US-ASCII for output
 -utf16le            use UTF-16LE for both input and output
 -utf16be            use UTF-16BE for both input and output
 -utf16              use UTF-16 for both input and output
 -big5               use Big5 for both input and output
 -shiftjis           use Shift_JIS for both input and output
 -language <lang>    set the two-letter language code <lang> (for future use)

Miscellaneous
-------------
 -version, -v        show the version of Tidy
 -help, -h, -?       list the command line options
 -xml-help           list the command line options in XML format
 -help-config        list all configuration options
 -xml-config         list all configuration options in XML format
 -show-config        list the current configuration settings

Use --blah blarg for any configuration option "blah" with argument "blarg"

Input/Output default to stdin/stdout respectively
Single letter options apart from -f may be combined
as in:  tidy -f errs.txt -imu foo.html
For further info on HTML see http://www.w3.org/MarkUp
狠疯拽 2024-07-13 22:23:38

您可以使用 HTML Agility Pack。 它来自 CodePlex 的开源项目。

You can use a HTML Agility Pack. Its open-source project from CodePlex.

软糯酥胸 2024-07-13 22:23:38

Validator.nu HTML Parser 附带一个 HTML2XML 示例程序,该程序使用 HTML5 解析算法进行转换和信息集强制规则。

The Validator.nu HTML Parser comes with an HTML2XML sample program that does the conversion using the HTML5 parsing algorithm and infoset coercion rules.

固执像三岁 2024-07-13 22:23:38

将 Html2Xhtml 用于 .NET 4.0:

内存中字符串到字符串转换:

var xhtml = Html2Xhtml.RunAsFilter(stdin => stdin.Write(html)).ReadToEnd();

内存中字符串到 XDocument 转换:

var xdoc = Html2Xhtml.RunAsFilter(stdin => stdin.Write(html)).ReadToXDocument();

请参阅 http://corsis.sourceforge.net/index.php/Html2Xhtml 了解更多信息。

Use Html2Xhtml for .NET 4.0:

In-memory string-to-string conversion:

var xhtml = Html2Xhtml.RunAsFilter(stdin => stdin.Write(html)).ReadToEnd();

In-memory string-to-XDocument conversion:

var xdoc = Html2Xhtml.RunAsFilter(stdin => stdin.Write(html)).ReadToXDocument();

See http://corsis.sourceforge.net/index.php/Html2Xhtml for more information.

梦里梦着梦中梦 2024-07-13 22:23:38

http://corsis.sourceforge.net/index.php/Html2Xhtmlhttp:// corsis.sourceforge.net/index.php/Html2Xhtml

Html2Xhtml 是一个 .NET 4.0 库,用于将 HTML 转换为 GPLv2 或更高版本许可的 XHTML。

我在欧盟大型在线数据库的本地重建中测试了Html2Xhtml。 Tidy/Tidy.NET 在大多数情况下甚至不会产生有效的输出,Chilkat 的 HTML 到 XML 有点慢并且产生奇怪的结果(放错位置、丢失、无法解释的元素)。 为了寻找一个免费、快速且可靠的转换工具,我创建了这个库。 它的转换速度比我测试的所有其他库快 2 - 4 倍。

Html2Xhtml 与 LINQ to XML 的强大功能相结合,是适用于所有大规模数据提取和 Web 爬行场景的出色工具。

http://corsis.sourceforge.net/index.php/Html2Xhtmlhttp://corsis.sourceforge.net/index.php/Html2Xhtml

Html2Xhtml is a .NET 4.0 library for converting HTML to XHTML licensed under GPLv2 or above.

I tested Html2Xhtml in the local reconstruction of a large online database of the European Union. Tidy/Tidy.NET would not even produce valid output most of the time, Chilkat's HTML-to-XML was a bit slow and produced strange results (misplaced, missing, unexplainable elements). In attempt to find a free, fast and reliable conversion tool I created this library. It converts 2 - 4x faster than all other libraries I tested.

Html2Xhtml, combined with the power of LINQ to XML, is an excellent tool for all large-scale data extraction and web crawling scenarios.

檐上三寸雪 2024-07-13 22:23:38

您可以使用 tidy 可执行文件将 html 转换为 xhtml:

tidy -asxhtml -numeric < 索引.html> index.xhml

您可以在此处检查 C# 实现。

you can convert html to xhtml with tidy executable file:

tidy -asxhtml -numeric < index.html > index.xhml

you can check the c# implementation here.

吃不饱 2024-07-13 22:23:38

最简单的方法是设置 Visual Studio IDE 以识别您需要进行的更改。
您可以在 Visual Studio 2008 中执行此操作,方法是:
工具、选项、文本编辑器、HTML、验证并选择适当的目标。
可能是 XHTML 1.1 或 XHTML 1.0 过渡。

有关不同类型的一些信息,请阅读:
http://msdn.microsoft.com/en-us/library/aa479043。 aspx

然后您需要处理页面上突出显示的点。

The easiest way is to set your Visual Studio IDE to identify the changes you need to make.
You can do this in Visual Studio 2008 by going to:
Tools, Options, Text Editor, HTML, Validation and choosing the appropriate target.
Possibly XHTML 1.1 or XHTML 1.0 Transitional.

For some information on the different types, read:
http://msdn.microsoft.com/en-us/library/aa479043.aspx

Then you need to work through the points highlighted on your page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文