如何HTML转换为XHTML? [关闭](How to convert HTML to XHTM

2019-07-05 04:03发布

我需要HTML文档转换成有效的XML,XHTML最好。 什么是做到这一点的最好方法是什么? 是否有人知道一个工具包/库/样品/ ...什么,可以帮助我得到这个任务呢?

在这里有点更清晰,我的应用程序在运行时自动进行转换。 我不寻找一个工具,可以帮助我一些页面手动移动到XHTML。

Answer 1:

从HTML转换成XML和HTML整洁

下载的二进制

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


Answer 2:

您可以使用HTML敏捷性包 。 CodePlex从它的开源项目。



Answer 3:

所述Validator.nu HTML解析器附带了不使用HTML5解析算法和信息集强制规则转换的HTML2XML示例程序。



Answer 4:

使用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以获取更多信息。



Answer 5:

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

Html2Xhtml是用于将HTML到XHTML的GPLv2或以上得到许可的.NET 4.0库。

我在欧盟的大型在线数据库的本地重建测试Html2Xhtml。 整理/ Tidy.NET甚至不会产生有效输出的大部分时间,奇尔卡特的HTML到XML的速度有点慢,并产生奇怪的结果(错位,丢失,无法解释的元素)。 在试图找到一个免费,快速和可靠的转换工具,我创造了这个库。 它把2 - 比我测试的所有其他库快4倍。

Html2Xhtml,与LINQ的力量XML结合,是所有大型数据提取和网页抓取场景的优秀工具。



Answer 6:

您可以将HTML与整洁的可执行文件到XHTML:

整齐-asxhtml -numeric <index.html的> index.xhml

您可以检查C#实现在这里 。



Answer 7:

最简单的方法是设置你的Visual Studio IDE中,以确定需要进行更改。 工具,选项,文本编辑器,HTML,验证并选择适当的目标:您可以通过在Visual Studio 2008中做到这一点。 可能XHTML 1.1或XHTML 1.0过渡。

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

然后,你需要通过强调自己的网页上点工作。



文章来源: How to convert HTML to XHTML? [closed]