Xml not parsing String as input with sax

后端 未结 5 1391
灰色年华
灰色年华 2021-02-14 10:31

I have a string input from which I need to extract simple information, here is the sample xml (from mkyong):



    &l         


        
5条回答
  •  情深已故
    2021-02-14 11:30

    Seems you took this example from here . You need to pass a file with absolute path an not a string to method SAXParser.parse(); Look the example closely. The method parse() defined as follows

    public void parse(File f,
                      DefaultHandler dh)
               throws SAXException,
                      IOException
    

    If you want to parse a string anyways. There is another method which takes Inputstream.

    public void parse(InputStream is,
                      DefaultHandler dh)
               throws SAXException,
                      IOException
    

    Then you need to convert your string to an InputStream. Here is how to do it.

提交回复
热议问题