2016-03-31 66 views
0

我有一個XML文件,如下所示:無法正確解析包含JAXB選項卡的XML文件?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<billFile fileName=".dat" hasHeader="false" fieldDelimiter=" "/> 

的fieldDelimiter包含一個標籤。當我調用Unmarshaller.unmarshal將此xml文件轉換爲對象時,該選項卡被替換爲空格。我希望它保持爲標籤。這裏是Java代碼,我有:

import java.io.StringReader; 

import javax.xml.bind.JAXBContext; 
import javax.xml.bind.JAXBException; 
import javax.xml.bind.Unmarshaller; 
import javax.xml.transform.stream.StreamSource; 


public class XMLToConfig 
{ 
    public static void main(String[] args) throws JAXBException 
    { 
    String input     = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <billFile fileName=\".dat\" hasHeader=\"false\" fieldDelimiter=\" \"/>"; 
    JAXBContext jaxbContext  = JAXBContext.newInstance(BillFile.class); 
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); 
    BillFile bf     = (BillFile)jaxbUnmarshaller.unmarshal(new StreamSource(new StringReader(input), "UTF8")); 
    } 
} 
+0

爲'input'被分配到一個字符串,使用' \ t'那麼 –

+0

使用\ t時出現同樣的問題。 – Wael

回答