我正在尝试将包含 " 的 XML 字符串解析为 SQL,但出现错误并且它使我的应用程序崩溃。
我尝试使用"
替换 " 但它在我的应用程序中创建错误。
有没有什么办法解决这一问题?
<drug>
<id>5</id>
<genericName>SIMVASTATIN</genericName>
<brandName>Zocor</brandName>
<therapueticClass>HMG-CoA Reductase Inhibitor/"statin"</therapueticClass>
<commonPurpose>reduce total-Cholesterol, LDL, TG and Increase HDL</commonPurpose>
<dosing>10-40mg daily</dosing>
<commonAE>Abdominal Pain</commonAE>
<blackBoxWarning>Liver Disease</blackBoxWarning>
<beersList>No</beersList>
<keyPoint>N/A</keyPoint>
<picture>drug.jpg</picture>
<drug>
Logcat:
08-28 16:46:11.733: D/dalvikvm(859): GC_FOR_ALLOC freed 46K, 7% free 2563K/2732K, paused 28ms, total 30ms
08-28 16:46:11.733: I/dalvikvm-heap(859): Grow heap (frag case) to 3.224MB for 635812-byte allocation
08-28 16:46:11.783: D/dalvikvm(859): GC_FOR_ALLOC freed 2K, 6% free 3181K/3356K, paused 48ms, total 48ms
08-28 16:46:11.843: D/dalvikvm(859): GC_CONCURRENT freed 1K, 5% free 3197K/3356K, paused 12ms+4ms, total 61ms
08-28 16:46:11.993: D/gralloc_goldfish(859): Emulator without GPU emulation detected.
08-28 16:46:13.843: E/SQLiteLog(859): (1) near "statin": syntax error
08-28 16:46:13.883: W/dalvikvm(859): threadid=11: thread exiting with uncaught exception (group=0x40a71930)
08-28 16:46:14.033: E/AndroidRuntime(859): FATAL EXCEPTION: AsyncTask #1
08-28 16:46:14.033: E/AndroidRuntime(859): java.lang.RuntimeException: An error occured while executing doInBackground()
08-28 16:46:14.033: E/AndroidRuntime(859): at android.os.AsyncTask$3.done(AsyncTask.java:299)
08-28 16:46:14.033: E/AndroidRuntime(859): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
08-28 16:46:14.033: E/AndroidRuntime(859): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
08-28 16:46:14.033: E/AndroidRuntime(859): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
08-28 16:46:14.033: E/AndroidRuntime(859): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-28 16:46:14.033: E/AndroidRuntime(859): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-28 16:46:14.033: E/AndroidRuntime(859): at java.lang.Thread.run(Thread.java:856)
08-28 16:46:14.033: E/AndroidRuntime(859): Caused by: android.database.sqlite.SQLiteException: near "statin": syntax error (code 1): , while compiling: INSERT INTO drugs (generic_name, brand_name, therapueticClass, commonPurpose, dosing, commonAE, blackBoxWarning, beersList, keyPoint, picture) values ("SIMVASTATIN", "Zocor", "HMG-CoA Reductase Inhibitor/"statin"", "reduce total-Cholesterol, LDL, TG and Increase HDL", "10-40mg daily", "Abdominal Pain", "Liver Disease", "No", "N/A", "drug.jpg");
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
08-28 16:46:14.033: E/AndroidRuntime(859): at edu.pacific.pocketrx.DrugDatabase.seedData(DrugDatabase.java:69)
08-28 16:46:14.033: E/AndroidRuntime(859): at edu.pacific.pocketrx.DrugDatabase.onCreate(DrugDatabase.java:52)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
08-28 16:46:14.033: E/AndroidRuntime(859): at edu.pacific.pocketrx.DrugProvider.query(DrugProvider.java:87)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.content.ContentProvider.query(ContentProvider.java:652)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.content.ContentProvider$Transport.query(ContentProvider.java:189)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.content.ContentResolver.query(ContentResolver.java:372)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.content.ContentResolver.query(ContentResolver.java:315)
08-28 16:46:14.033: E/AndroidRuntime(859): at edu.pacific.pocketrx.MainActivity$LoadDrugsTask.doInBackground(MainActivity.java:78)
08-28 16:46:14.033: E/AndroidRuntime(859): at edu.pacific.pocketrx.MainActivity$LoadDrugsTask.doInBackground(MainActivity.java:1)
08-28 16:46:14.033: E/AndroidRuntime(859): at android.os.AsyncTask$2.call(AsyncTask.java:287)
08-28 16:46:14.033: E/AndroidRuntime(859): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
08-28 16:46:14.033: E/AndroidRuntime(859): ... 4 more
编辑:我可以通过将这行代码更改为以下代码来使用引号:
<therapueticClass>HMG-CoA Reductase Inhibitor/""statin""</therapueticClass>