XML String parsing in Android?

后端 未结 2 1268
谎友^
谎友^ 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);
    
    0 讨论(0)
  • 2021-02-05 11:09

    You can use StringReader :

    StringReader sr = new StringReader(xml);
    InputSource is = new InputSource(sr);
    Document d = builder.parse(is);
    
    0 讨论(0)
提交回复
热议问题