XML String parsing in Android?

后端 未结 2 1270
谎友^
谎友^ 2021-02-05 10:31

I use the following code to parse the XML file.

DocumentBuilderFactory factory;
DocumentBuilder builder;
InputStream is;
Document dom;
try {
    factory = Docume         


        
2条回答
  •  梦如初夏
    2021-02-05 11:05

    You can convert your string to an InputStream using ByteArrayInputStream:

    String xml ="valid xml here";
    InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
    
    dom = builder.parse(is);
    

提交回复
热议问题