문제

HTML 문서를 유효한 XML, 바람직하게는 XHTML로 변환해야 합니다.이를 수행하는 가장 좋은 방법은 무엇입니까?툴킷/라이브러리/샘플/...해당 작업을 완료하는 데 도움이 되는 것이 무엇인지 아는 사람이 있나요?

여기서 좀 더 명확하게 설명하면 내 애플리케이션은 런타임에 자동으로 변환을 수행해야 합니다.일부 페이지를 XHTML로 수동으로 이동하는 데 도움이 되는 도구를 찾지 않습니다.

도움이 되었습니까?

해결책

HTML Tidy를 사용하여 HTML에서 XML로 변환하십시오

다운로드 가능한 바이너리

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

다른 팁

당신은 a를 사용할 수 있습니다 HTML 민첩성 팩. CodePlex의 오픈 소스 프로젝트.

그만큼 validator.nu html 파서 HTML5 구문 분석 알고리즘 및 INFOSET 강요 규칙을 사용하여 변환을 수행하는 HTML2XML 샘플 프로그램이 제공됩니다.

.NET 4.0에는 html2xhtml을 사용하십시오.

메모리 내 문자열-스트링 변환 :

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 자세한 내용은.

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

Html2Xhtml은 GPLv2 이상에 따라 라이센스가 부여된 HTML을 XHTML로 변환하기 위한 .NET 4.0 라이브러리입니다.

나는 유럽 연합의 대규모 온라인 데이터베이스를 로컬로 재구성하면서 Html2Xhtml을 테스트했습니다.Tidy/Tidy.NET은 대부분의 경우 유효한 출력을 생성하지도 않습니다. Chilkat의 HTML-to-XML은 약간 느리고 이상한 결과(잘못 배치, 누락, 설명할 수 없는 요소)를 생성했습니다.빠르고 안정적인 무료 변환 도구를 찾기 위해 이 라이브러리를 만들었습니다.제가 테스트한 다른 모든 라이브러리보다 2~4배 빠르게 변환됩니다.

LINQ to XML의 강력한 기능과 결합된 Html2Xhtml은 모든 대규모 데이터 추출 및 웹 크롤링 시나리오를 위한 탁월한 도구입니다.

깔끔한 실행 파일로 html을 xhtml로 변환 할 수 있습니다.

Tidy -asxhtml -Numeric <Index.html> index.xhml

C# 구현을 확인할 수 있습니다 여기.

가장 쉬운 방법은 시각적 스튜디오를 설정하여 필요한 변경 사항을 식별하는 것입니다. 도구, 옵션, 텍스트 편집기, HTML, 유효성 검사 및 적절한 대상 선택으로 이동하여 Visual Studio 2008 에서이 작업을 수행 할 수 있습니다. 아마도 XHTML 1.1 또는 XHTML 1.0 전환.

다른 유형에 대한 일부 정보는 다음과 같이 읽으십시오.http://msdn.microsoft.com/en-us/library/aa479043.aspx

그런 다음 페이지에서 강조 표시된 포인트를 통해 작업해야합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top