2013-02-17 22 views
11

strings.xml संसाधन में CDATA का उपयोग कर मैं अपने Android परियोजना में एक स्ट्रिंग संसाधन है, और मुझे एक्सएमएल में मेरी स्ट्रिंग एम्बेड करने के लिए एक CDATA अनुभाग का उपयोग कर रहा:त्रुटि! एंड्रॉयड

<string name="ackng"><![CDATA[ 
    <html> 
<body> 
    <h1>Acknowledgements</h1> 
    <p> 
     Senator Paul Wellstone's book, the Conscience of a Liberal: Reclaiming the 
     compassionate agenda was an inspiration and an affirmation that you can be truthful 
     and honest as a politician, and compassionate and people-centred as a representative. 
     And as President Bill Clinton affirmed as he addressed the joint session of the 
     National Assembly on 26th August, 2000, thus: 
     “Every nation that has struggled to build democracy has found that success 
     depends on leaders who believe government exists to serve people, not the 
     other way around.” 
    </p> 
    <p> 
     Paul Wellstone's book was my inspiration for the launching of the compassionate 
     agenda in February 2002. Clinton's speech affirmed my convictions regarding the 
     sanctity of the democratic mandate to serve the people. I acknowledge the clarity of 
     their focus and the inspiration their works continue to provide. 
    </p> 
</body></html>]]></string> 

लेकिन eclispe इस त्रुटि लौट रहा है:

[2013-02-18 00:11:05 - MyPA] C:\Users\Daniel\workspace\MyPA\res\values\strings.xml:191: error: Apostrophe not preceded by \ (in <html> 

उत्तर

12

अपॉस्ट्राफी (') \ का उपयोग कर भाग निकले किया जाना चाहिए। अपने स्ट्रिंग की सामग्री में ' के बजाय \' का उपयोग करने का प्रयास करें। apostrophe की

“Every nation that has struggled to build democracy has found that success 
depends on leaders who believe government exists to serve people, not the 
other way around.” 
7

उपयोग &#39; बजाय:

इसके अलावा, आप \" साथ निम्नलिखित भाग में " से बचने के लिए की आवश्यकता होगी। HTML आउटपुट (मुझे लगता है कि यह HTML है) के मामले में चरित्र का प्रभाव है। तो &#39;' के रूप में प्रदर्शित किया जाएगा।

+0

मुझे नहीं पता कि किसने इसे वोट दिया है, लेकिन यह * सही * +1 है ... +1 – Ahmad

8

String Formatting and Styling कहते

Escaping apostrophes and quotes

If you have an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other type of enclosing quotes. For example, here are some stings that do and don't work:

<string name="good_example">"This'll work"</string> 
<string name="good_example_2">This\'ll also work</string> 
<string name="bad_example">This doesn't work</string> 
<string name="bad_example_2">XML encodings don&apos;t work</string> 

यह bad_example_2 तरह लग रहा है आपकी समस्या का वर्णन करता है। राघव सूद द्वारा सुझाए गए अनुसार और \" दोनों के साथ ' और " दोनों को good_example_2 की प्रतिलिपि बनाने के लिए आपकी सबसे अच्छी शर्त है।

+1

मुझे लगता है कि एचटीएमएल कोड रखने के लिए का उपयोग करके इसे एस्ट्रोफ़े –

+1

@mister_dani जैसी समस्याओं के प्रति प्रतिरोध प्रदान करें, मेरी समझ यह है कि सीडीएटीए सेक्शन एक्सएमएल पार्सर को एक्सएमएल की स्ट्रिंग से टेक्स्ट नोड कैसे प्राप्त करता है, लेकिन यह दस्तावेज इंगित करता है कि एक्सएमएल दस्तावेज़ प्रोसेसर एक्सएमएल एस्केपिंग से अलग एक विशेष एस्केपिंग कन्वेंशन का उपयोग करने के लिए टेक्स्ट नोड्स (पार्सिंग के बाद) की अपेक्षा करता है। –

+0

@ मिस्टर_दानी नहीं, इसका अनजान लेकिन सीडीएटीए एस्ट्रोफ़े के साथ मदद नहीं करता है, आपको इसे से बचने की भी आवश्यकता है। – for3st