How to make SAXParser ignore escape codes

后端 未结 4 668
没有蜡笔的小新
没有蜡笔的小新 2021-01-22 22:06

I am writing a Java program to read and XML file, actually an iTunes library which is XML plist format. I have managed to get round most obstacles that this format throws up exc

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-22 22:25

    It's probably not the best general solution for escape characters, but I only had to take into account new lines so it was easy to just check for \n.

    You could check for the backslash \ only to check for all escape characters or in your case &, although I think others will come with more elegant solutions.

    @Override
    public void characters(char[] ch, int start, int length) 
    {
        String elementData = new String(ch, start, length);
        boolean elementDataContainsNewLine = (elementData.indexOf("\n") != -1);
    
        if (!elementDataContainsNewLine) 
        {
            //do what you want if it is no new line
        }
    }
    

提交回复
热议问题