2008-09-26 18 views
21

मुझे HTML दस्तावेज़ों को वैध XML, अधिमानतः एक्सएचटीएमएल में परिवर्तित करने की आवश्यकता है। ऐसा करने का सबसे अच्छा तरीका क्या है? क्या किसी को टूलकिट/लाइब्रेरी/नमूना/पता है ... जो कुछ भी मुझे यह काम करने में मदद करता है?एचटीएमएल से एक्सएचटीएमएल कैसे परिवर्तित करें?

यहां थोड़ा और स्पष्ट होने के लिए, मेरे एप्लिकेशन को रनटाइम पर स्वचालित रूप से रूपांतरण करना है। मैं ऐसे टूल की तलाश नहीं करता जो मुझे कुछ पृष्ठों को मैन्युअल रूप से एक्सएचटीएमएल में स्थानांतरित करने में मदद करता है।

उत्तर

23

Convert from HTML to XML with HTML Tidy

Downloadable Binaries

JRoppert, अपनी जरूरत के लिए, मैं लगता है कि आप 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 
0

सबसे आसान तरीका है की पहचान करने के लिए अपने विजुअल स्टूडियो IDE स्थापित करने के लिए है को देखने के लिए चाहते हो सकता है परिवर्तन जो आपको करने की ज़रूरत है। आप इसे विजुअल स्टूडियो 2008 में कर सकते हैं: उपकरण, विकल्प, टेक्स्ट संपादक, एचटीएमएल, सत्यापन और उचित लक्ष्य चुनना। संभावित रूप से एक्सएचटीएमएल 1.1 या एक्सएचटीएमएल 1.0 संक्रमणकालीन।

विभिन्न प्रकार पर कुछ जानकारी के लिए, पढ़ें: http://msdn.microsoft.com/en-us/library/aa479043.aspx

तो फिर तुम अंक अपने पृष्ठ पर प्रकाश डाला के माध्यम से काम करने की जरूरत।

+0

क्षमा करें, मैं अपने प्रश्न में स्पष्ट नहीं था। मुझे रनटाइम पर रूपांतरण स्वचालित रूप से करने की आवश्यकता है। – JRoppert

6

आप HTML Agility Pack का उपयोग कर सकते हैं। कोडप्लेक्स से इसकी ओपन-सोर्स प्रोजेक्ट।

4

Validator.nu HTML Parser एक HTML2XML नमूना प्रोग्राम के साथ आता है जो HTML5 पार्सिंग एल्गोरिदम और इंफोसेट जबरन नियमों का उपयोग करके रूपांतरण करता है।

4

उपयोग 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

+0

मेरे पास एक ही सवाल था और इस जवाब का इस्तेमाल किया, यह खूबसूरती से काम करता है। विशेष रूप से XElement में रूपांतरण के लिए। – Beaker

2

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

Html2Xhtml एचटीएमएल परिवर्तित करने के लिए एक .NET 4.0 पुस्तकालय GPLv2 के तहत या इसके बाद के संस्करण लाइसेंस प्राप्त XHTML है।

मैंने यूरोपीय संघ के एक बड़े ऑनलाइन डेटाबेस के स्थानीय पुनर्निर्माण में Html2Xhtml का परीक्षण किया। साफ-सुथरा/Tidy.NET अधिकांश समय तक वैध आउटपुट का उत्पादन नहीं करेगा, चिलकट का एचटीएमएल-टू-एक्सएमएल थोड़ा धीमा था और अजीब परिणाम उत्पन्न हुआ (गलत, लापता, अस्पष्ट तत्व)। एक मुफ्त, तेज़ और भरोसेमंद रूपांतरण उपकरण खोजने के प्रयास में मैंने इस पुस्तकालय को बनाया है। यह परीक्षण किए गए सभी अन्य पुस्तकालयों की तुलना में 2 - 4x तेज रूपांतरित करता है।

एचटीएमएल 2 एक्सएचटीएमएल, जो LINQ से XML की शक्ति के साथ संयुक्त है, सभी बड़े पैमाने पर डेटा निष्कर्षण और वेब क्रॉलिंग परिदृश्यों के लिए एक उत्कृष्ट उपकरण है।

साफ -asxhtml -numeric < सूचकांक:

2

आप साफ निष्पादन योग्य फ़ाइल के साथ XHTML में एचटीएमएल बदल सकते हैं।एचटीएमएल> index.xhml

आप सी # कार्यान्वयन here देख सकते हैं।

संबंधित मुद्दे