Eclipse表现得很奇怪

时间:2013-11-05 11:38:07

标签: android eclipse dom domparser

我有一个需要dom解析的应用程序,应用程序在我的同事的机器上正常运行但在我的机器上它抛出了saxexception(意外的令牌)。任何想法为什么日食表现得很奇怪。以下是我如何阅读我的xml文件的方法。

private String readFile() throws Exception{
        AssetManager assetManager = activity.getAssets();
        InputStream ims = assetManager.open("temp/MyXml.xml");

        StringBuffer fileContent = new StringBuffer("");

        byte[] buffer = new byte[1024];

        while (ims.read(buffer) != -1) {
            fileContent.append(new String(buffer));
        }

        return fileContent.toString();
    }

以下是解析方法。

private Document getDomElement(String xml) throws Exception {

        Document doc = null;
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        try {

            DocumentBuilder db = dbf.newDocumentBuilder();

            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(xml));
            doc = db.parse(is);

        } catch (ParserConfigurationException e) {
            throw e;
        } catch (SAXException e) {
            throw e;
        } catch (IOException e) {
            throw e;
        }
        // return DOM
        return doc;
    }

和堆栈跟踪

11-05 17:16:30.200: W/System.err(12283): org.xml.sax.SAXParseException: Unexpected token (position:TEXT 
11-05 17:16:30.200: W/System.err(12283): URRICANE DISH D...@2:237 in java.io.StringReader@2bdda808) 
11-05 17:16:30.200: W/System.err(12283):    at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:146)
11-05 17:16:30.200: W/System.err(12283):    at org.col.gsso.sap.parser.InputDataXMLParser.getDomElement(InputDataXMLParser.java:510)
11-05 17:16:30.200: W/System.err(12283):    at org.col.gsso.sap.parser.InputDataXMLParser.saveInputFiles(InputDataXMLParser.java:106)
11-05 17:16:30.200: W/System.err(12283):    at com.gps.colpal.ToPalmDownloadAsycTask.doInBackground(ToPalmDownloadAsycTask.java:103)
11-05 17:16:30.200: W/System.err(12283):    at com.gps.colpal.ToPalmDownloadAsycTask.doInBackground(ToPalmDownloadAsycTask.java:1)
11-05 17:16:30.200: W/System.err(12283):    at android.os.AsyncTask$2.call(AsyncTask.java:264)
11-05 17:16:30.200: W/System.err(12283):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-05 17:16:30.200: W/System.err(12283):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-05 17:16:30.200: W/System.err(12283):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-05 17:16:30.200: W/System.err(12283):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-05 17:16:30.200: W/System.err(12283):    at java.lang.Thread.run(Thread.java:856)
11-05 17:16:30.250: W/IInputConnectionWrapper(12283): finishComposingText on inactive InputConnection

0 个答案:

没有答案