Frage

Ich brauche HTML-Dokumente in gültige XML zu konvertieren, vorzugsweise XHTML. Was ist der beste Weg, dies zu tun? Kennt jemand ein Toolkit / Bibliothek / sample / ... was auch immer das hilft mir diese Aufgabe zu erledigen?

Um ein bisschen mehr klar hier zu sein, meine Anwendung hat die Konvertierung automatisch zur Laufzeit zu tun. Ich sehe nicht ein Werkzeug, das mir hilft, einige Seiten zu bewegen, manuell XHTML.

War es hilfreich?

Lösung

aus HTML Konvertieren mit HTML Tidy in XML

Herunterladen Binaries

JRoppert, für Ihren Bedarf, ich denke, man könnte auf die Quellen

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

Andere Tipps

Sie können eine HTML Agility Pack- verwenden. Sein Open-Source-Projekt von CodePlex.

Der Validator.nu HTML-Parser kommt mit einem HTML2XML Beispielprogramm, das die Konvertierung mit funktioniert die HTML5 Parsing-Algorithmus und infoset Zwang Regeln.

Verwenden Html2Xhtml für .NET 4.0:

In-Memory-String-to-String-Konvertierung:

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

In-Memory-String-to-XDocument Umwandlung:

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

Siehe http://corsis.sourceforge.net/index.php/Html2Xhtml für weitere Informationen.

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

Html2Xhtml ist eine .NET 4.0-Bibliothek für HTML zu XHTML lizenziert unter GPLv2 Umwandlung oder höher.

I getestet Html2Xhtml in der lokalen Rekonstruktion einer großen Online-Datenbank der Europäischen Union. Tidy / Tidy.NET würde nicht einmal gültige Ausgabe die meiste Zeit produzieren, Chilkat HTML-to-XML war ein bisschen langsam und produziert seltsame Ergebnisse (fehl am Platz, fehlen, unerklärliche Elemente). Im Versuch, ein kostenloses, schnelles und zuverlässiges Umwandlung Werkzeug zu finden habe ich diese Bibliothek. Er wandelt. 2 - 4x schneller als alle anderen Bibliotheken, die ich getestet

Html2Xhtml, mit der Leistung von LINQ to XML kombiniert, ist ein ausgezeichnetes Werkzeug für alle großen Datenextraktion und Web-Crawling-Szenarien.

Sie können html xhtml mit ordentlich ausführbare Datei konvertieren:

ordentlich -asxhtml -numeric index.xhml

können Sie die c # -Implementierung hier .

Der einfachste Weg ist der Visual Studio IDE können Sie die Änderungen, die Sie vornehmen müssen zu identifizieren. Sie können in Visual Studio 2008 tun dies, indem Sie auf: Extras, Optionen, Text-Editor, HTML, Validierung und das entsprechende Ziel wählen. Möglicherweise XHTML 1.1 oder XHTML 1.0.

Für einige Informationen über die verschiedenen Arten, lesen: http://msdn.microsoft.com/en-us/library/aa479043. aspx

Dann müssen Sie durch die Punkte auf der Seite hervorgehoben arbeiten.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top