2012-06-28 5 views
6

में br टैग कैसे निम्नलिखित लाइनों में br टैग के बाद पाठ को निकालने के लिए के बाद पाठ को निकालने के लिए:XPath आर

<div id='population'> 
    The Snow Leopard Survival Strategy (McCarthy <em>et al.</em> 2003, Table 
    II) compiled national snow leopard population estimates, updating the work 
    of Fox (1994). Many of the estimates are acknowledged to be rough and out 
    of date, but the total estimated population is 4,080-6,590, as follows:<br> 
    <br> 
    Afghanistan: 100-200?<br> 
    Bhutan: 100-200?<br> 
    China: 2,000-2,500<br> 
    India: 200-600<br> 
    Kazakhstan: 180-200<br> 
    Kyrgyzstan: 150-500<br> 
    Mongolia: 500-1,000<br> 
    Nepal: 300-500<br> 
    Pakistan: 200-420<br> 
    Russia: 150-200<br> 
    Tajikistan: 180-220<br> 
    Uzbekistan: 20-50 
</div> 

मुझे मिल गया जहाँ तक:

xpathSApply(h, '//div[@id="population"]', xmlValue) 

लेकिन मैं अटक कर रहा हूँ अब ...

+3

यहां कोई टेक्स्ट _within_ '
टैग नहीं है ... क्या आपका मतलब है _between_ कई टैग? आप यह स्पष्ट करना चाहते हैं कि आप _exactly_ क्या चाहते हैं। पहला अनुमान होगा '// div [@ id = "आबादी"]/पाठ() [preceding-sibling :: br]' ' – Wrikken

+0

यह है! इसे एक उत्तर के रूप में रखें और मैं इसे देखूंगा – Kay

उत्तर

18

यदि आपको लगता है कि पाठ नोड भी है तो यह मदद करता है। div में सभी पाठ से <br/> 'इस प्रकार रों के द्वारा प्राप्त किया जा सकता है:

//div[@id="population"]/text()[preceding-sibling::br] 

तकनीकी तौर पर, <br/> के बीच टैग का मतलब होगा:

//div[@id="population"]/text()[preceding-sibling::br and following-sibling::br] 

... लेकिन मुझे लगता है कि यह है कि आप क्या चाहते हैं नहीं है इस समय।

+0

मैंने 'बीच' संपादित किया .. बहुत बहुत धन्यवाद! – Kay