سؤال

أحتاج إلى تحويل مستندات HTML إلى XML صالح، ويفضل XHTML.ما هي الطريقة الأفضل لعمل هذا؟هل يعرف أحد مجموعة أدوات/مكتبة/عينة/...أي شيء يساعدني في إنجاز هذه المهمة؟

لكي أكون أكثر وضوحًا هنا، يجب أن يقوم تطبيقي بإجراء التحويل تلقائيًا في وقت التشغيل.لا أبحث عن أداة تساعدني في نقل بعض الصفحات إلى XHTML يدويًا.

هل كانت مفيدة؟

المحلول

التحويل من HTML إلى XML باستخدام HTML Tidy

الثنائيات القابلة للتحميل

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

نصائح أخرى

يمكنك استخدام أ حزمة أجيليتي HTML.مشروع مفتوح المصدر من CodePlex.

ال Validator.nu محلل HTML يأتي مع نموذج برنامج HTML2XML الذي يقوم بالتحويل باستخدام خوارزمية تحليل HTML5 وقواعد إكراه مجموعة المعلومات.

استخدم 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 للمزيد من المعلومات.

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

Html2Xhtml هي مكتبة .NET 4.0 لتحويل HTML إلى XHTML مرخصة بموجب GPLv2 أو أعلى.

لقد اختبرت Html2Xhtml في إعادة البناء المحلي لقاعدة بيانات كبيرة على الإنترنت تابعة للاتحاد الأوروبي.لم يكن Tidy/Tidy.NET ينتج حتى مخرجات صالحة في معظم الأوقات، وكان تحويل HTML إلى XML الخاص بـ Chilkat بطيئًا بعض الشيء وأدى إلى نتائج غريبة (عناصر في غير محلها، ومفقودة، وغير قابلة للتفسير).في محاولة للعثور على أداة تحويل مجانية وسريعة وموثوقة، قمت بإنشاء هذه المكتبة.إنه يحول 2 - 4 مرات أسرع من جميع المكتبات الأخرى التي اختبرتها.

يعد Html2Xhtml، بالإضافة إلى قوة LINQ إلى XML، أداة ممتازة لجميع سيناريوهات استخراج البيانات والزحف على الويب على نطاق واسع.

يمكنك تحويل html إلى xhtml باستخدام ملف قابل للتنفيذ مرتب:

مرتب -asxhtml -numeric <index.html> Index.xhml

يمكنك التحقق من تنفيذ C# هنا.

أسهل طريقة هي تعيين Visual Studio IDE الخاص بك لتحديد التغييرات التي تحتاج إلى إجرائها.يمكنك القيام بذلك في Visual Studio 2008 بالانتقال إلى:الأدوات، الخيارات، محرر النصوص، HTML، التحقق من الصحة واختيار الهدف المناسب.ربما XHTML 1.1 أو XHTML 1.0 انتقالي.

للحصول على بعض المعلومات حول الأنواع المختلفة، اقرأ:http://msdn.microsoft.com/en-us/library/aa479043.aspx

ثم تحتاج إلى العمل من خلال النقاط المميزة على صفحتك.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top