2013-03-29 35 views
2

這裏是我想改變我的XML文件的一部分...... 這個文件並不存儲在我的項目的資產,它是在網絡 xml文件我用了XMLPull解析器解析如何替換&,<字符爲&,<解析後的xml文件爲android?

<exclusion_criteria> 
Poor condition (centre determined), acute leukemia in relapse (&lt10% blasts), second transplants, active infection, HIV infection, T-cell antibody prophylaxis (antithymocyte globulin, anti-CD52 etc), use of cord blood grafts, T-cell depletion of grafts 
      </exclusion_criteria> 
     </report> 

     <report> 

      <tumour_disease> 
Bone Marrow Transplants 
      </tumour_disease> 

      <trial_status> 
Active- Recruiting 
      </trial_status> 

      <short_title> 
Haplo Transplants 
      </short_title> 

      <title> 
Haploidentical donor stem cell transplantatation for myeloid malignancies - a phase I/II pilot study in an Australian population 
      </title> 

      <trial_register_number> 
      </trial_register_number> 

      <sponsors> 
St Vincents Hospital 
      </sponsors> 

      <trial_phase> 
Phase I/II 
      </trial_phase> 

      <locations> 
St Vincents Hospital~ 
      </locations> 

      <lead_site> 
St Vincents Hospital 
      </lead_site> 

      <inclusion_criteria> 
Patients aged 16-50 years with haematological malignancy requiring stem cell transplantation (acute myeloid leukaemia in CR1 or CR2, intermediate-high risk myelodysplasia, chronic myeloid leukaemia in CP2-resistant to TKIs, relapsed and refractory lymphoproliferative diseases or Hodgkins lymphomas) lacking a fully HLA-matched donor; with a partially (=5/6) HLA-mismatched donor; adequate organ function (cardiac, pulmonary, renal & hepatic 
      </inclusion_criteria> 

      <exclusion_criteria> 
Life expectancy < 3months; psychiatric conditioning impairing provision of informed consent; active malignant disease (excluding BCC and SCC; receiving concurrent investigational drugs; pregnant or lactating women 
      </exclusion_criteria> 
+0

,我也有一個同樣的問題,「&」符號 – Sakthimuthiah

回答

0

參照此:XmlPullParser

你在尋找這樣的事情:

if(eventType == XmlPullParser.TEXT) 
{ 
    String text = xpp.getText(); 
    if(text.contains("&")) 
     text = text.replace("&", "&amp;"); 
    if(text.contains("<")) 
     text = text.replace("<", "&lt;"); 
} 

編輯: 這裏是你如何獲取XML在String

String xmlStr = ""; 

HttpGet uri = new HttpGet(params[0]); 

DefaultHttpClient client = new DefaultHttpClient(); 

HttpResponse resp = client.execute(uri); 
StatusLine status = resp.getStatusLine(); 
if(status.getStatusCode() == 200) 
{ 
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
    DocumentBuilder builder = factory.newDocumentBuilder(); 
    Document doc = builder.parse(resp.getEntity().getContent()); 

    TransformerFactory transformerfactory = TransformerFactory.newInstance(); 
    Transformer transformer = transformerfactory.newTransformer(); 
    transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 

    StringWriter stringWriter = new StringWriter(); 
    transformer.transform(new DOMSource(doc), new StreamResult(stringWriter)); 

    // Now you can fix the invalid characters in your xml and put it in the parser 
    xmlStr = stringWriter.toString(); 
}   
+0

我已經使用了,但我的文本包含&,<符號,以便它給出了xpp.getText異常(),而不是繼續進行if(text.contains())...... –

+0

我編輯了答案:通過該方法,您可以將xml文件加載到一個String變量中,並通過修改其內容並將其傳遞給xmlpullparser。希望這可以幫助... – vilpe89

相關問題