Question

Je dois convertir des documents HTML en XML valide, de préférence XHTML. Quelle est la meilleure façon de faire cela? Est-ce que quelqu'un connaît une boîte à outils / bibliothèque / échantillon / ... tout ce qui m'aide à accomplir cette tâche?

Pour être un peu plus clair ici, mon application doit faire la conversion automatiquement à l'exécution. Je ne cherche pas d'outil qui m'aide à déplacer manuellement certaines pages en XHTML.

Était-ce utile?

La solution

Convertir du HTML en XML avec HTML Tidy a>

Fichiers binaires téléchargeables

JRoppert, Pour répondre à vos besoins, vous pouvez consulter les 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

Autres conseils

Vous pouvez utiliser un Pack d'agilité HTML . Son projet open-source de CodePlex.

L’ Validator.nu HTML Parser est fourni avec un exemple de programme HTML2XML qui effectue la conversion à l'aide de Algorithme d'analyse HTML5 et règles de coercition de l'ensemble d'information.

Utilisez Html2Xhtml pour .NET 4.0:

Conversion de mémoire en chaîne:

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

Conversion de chaîne en mémoire XDocument:

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

Voir http://corsis.sourceforge.net/index.php/Html2Xhtml pour plus d'informations.

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

Html2Xhtml est une bibliothèque .NET 4.0 pour la conversion de HTML en XHTML sous licence GPLv2 ou supérieure.

J'ai testé Html2Xhtml lors de la reconstruction locale d'une grande base de données en ligne de l'Union européenne. Tidy / Tidy.NET ne produirait même pas une sortie valide la plupart du temps, le HTML-to-XML de Chilkat était un peu lent et produisait des résultats étranges (éléments mal placés, manquants, inexplicables). Pour tenter de trouver un outil de conversion gratuit, rapide et fiable, j'ai créé cette bibliothèque. Il convertit 2 à 4 fois plus rapidement que toutes les autres bibliothèques que j'ai testées.

Html2Xhtml, associé à la puissance de LINQ to XML, constitue un excellent outil pour tous les scénarios d'extraction de données à grande échelle et d'analyse Web.

vous pouvez convertir html en xhtml avec le fichier exécutable bien rangé:

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

vous pouvez vérifier la mise en œuvre de c # ici .

La méthode la plus simple consiste à configurer votre IDE Visual Studio afin qu’il identifie les modifications à apporter. Vous pouvez le faire dans Visual Studio 2008 en allant à: Outils, Options, Éditeur de texte, HTML, Validation et choix de la cible appropriée. Peut-être XHTML 1.1 ou XHTML 1.0 Transitional.

Pour des informations sur les différents types, lisez: http://msdn.microsoft.com/en-us/library/aa479043. aspx

Ensuite, vous devez vous attaquer aux points mis en évidence sur votre page.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top