Come convertire HTML in XHTML? [chiuso]
Domanda
Devo convertire documenti HTML in XML validi, preferibilmente XHTML. Qual'è il miglior modo per farlo? Qualcuno conosce un toolkit / library / sample / ... qualunque cosa mi aiuti a svolgere questo compito?
Per essere un po 'più chiaro qui, la mia applicazione deve eseguire automaticamente la conversione in fase di esecuzione. Non cerco uno strumento che mi aiuti a spostare manualmente alcune pagine in XHTML.
Soluzione
Converti da HTML a XML con HTML Tidy
JRoppert, per le tue necessità, immagino che potresti voler esaminare le Sorgenti
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
Altri suggerimenti
Puoi usare un HTML Agility Pack . Il suo progetto open source di CodePlex.
Validator.nu HTML Parser viene fornito con un programma di esempio HTML2XML che esegue la conversione utilizzando il Algoritmo di analisi HTML5 e regole di coercizione infoset.
Usa Html2Xhtml per .NET 4.0:
Conversione da stringa a stringa in memoria:
var xhtml = Html2Xhtml.RunAsFilter(stdin => stdin.Write(html)).ReadToEnd();
Conversione da stringa a X di documenti in memoria:
var xdoc = Html2Xhtml.RunAsFilter(stdin => stdin.Write(html)).ReadToXDocument();
Vedi http://corsis.sourceforge.net/index.php/Html2Xhtml per ulteriori informazioni.
http://corsis.sourceforge.net/index.php/Html2Xhtml http : //corsis.sourceforge.net/index.php/Html2Xhtml
Html2Xhtml è una libreria .NET 4.0 per convertire HTML in XHTML concesso in licenza con GPLv2 o superiore.
Ho testato Html2Xhtml nella ricostruzione locale di un ampio database online dell'Unione Europea. Tidy / Tidy.NET non produrrebbe nemmeno un output valido per la maggior parte del tempo, l'HTML-to-XML di Chilkat era un po 'lento e produceva strani risultati (elementi fuori posto, mancanti, inspiegabili). Nel tentativo di trovare uno strumento di conversione gratuito, veloce e affidabile ho creato questa libreria. Converte 2 - 4x più velocemente di tutte le altre librerie che ho testato.
Html2Xhtml, combinato con la potenza di LINQ to XML, è uno strumento eccellente per tutti gli scenari di estrazione dei dati su larga scala e di scansione del Web.
puoi convertire html in xhtml con un file eseguibile ordinato:
tidy -asxhtml -numeric < index.html > index.xhml
puoi controllare l'implementazione di c # qui .
Il modo più semplice è impostare l'IDE di Visual Studio per identificare le modifiche che è necessario apportare. Puoi farlo in Visual Studio 2008 andando a: Strumenti, Opzioni, Editor di testo, HTML, Convalida e scelta del target appropriato. Forse XHTML 1.1 o XHTML 1.0 Transitional.
Per alcune informazioni sui diversi tipi, leggi: http://msdn.microsoft.com/en-us/library/aa479043. aspx
Quindi devi esaminare i punti evidenziati nella tua pagina.