Reading escape characters with XMLStreamReader

前端 未结 2 1473
感情败类
感情败类 2021-01-05 15:20

Hi I have a problem reading escape characters inside an xml using XMLStreamReader.

for instance I have this element :

foo&bar         


        
2条回答
  •  孤独总比滥情好
    2021-01-05 15:52

    To force XMLStreamReader to return a single string, you have to set the javax.xml.stream.isCoalescing property as indicated by the XMLStreamReader#next() documentation:

    XMLInputFactory factory = XMLInputFactory.newInstance();
    factory.setProperty("javax.xml.stream.isCoalescing", true);  // decode entities into one string
    XMLStreamReader xmlStreamReader = factory.createXMLStreamReader(stringReader);
    

提交回复
热议问题