[英]Inserting a large amount of XML data in my SQLite database
I am making an app in Android which communicates with a .NET Webservice to get Data. 我正在用Android开发一个与.NET Web服务通信以获取数据的应用程序。
I have got data in XML format and also parsed it, but I am not able to insert it into my SQLite database. 我已经获得了XML格式的数据并进行了解析,但是无法将其插入到SQLite数据库中。
The data amount is very large and I am confused on how to insert so many data through looping. 数据量非常大,我对如何通过循环插入这么多数据感到困惑。
The XML data is in the following format. XML数据采用以下格式。
<NewData>
<Table>
<First Name>Sangeeta</ First Name>
<Second Name>Rawat</Second Name>
<Designation>Tester</Designation>
.
.
.
</Table>
</New Data>
my code is 我的代码是
public static void invokeHelloWorldWS(String webMethName,Context context) {
String resTxt = null;
mDbHelper = new TestAdapter(context);
// Create request
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, webMethName);
// Property which holds input parameters
//PropertyInfo celsiusPI = new PropertyInfo();
// Set Name
////celsiusPI.setName("name");
// Set Value
//celsiusPI.setValue(name);
// Set dataType
//celsiusPI.setType(String.class);
// Add the property to request object
//request.addProperty(celsiusPI);
//request.addProperty("Content-Type", "text/xml; charset=utf-8");
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE (SOAP_ADDRESS);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
String xml = androidHttpTransport.responseDump;
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput( new StringReader ( xml ) );
Log.e("xml", "loaded");
int eventType = xpp.getEventType();
xpp.require(XmlPullParser.START_DOCUMENT, null, null);
while (xpp.next() != XmlPullParser.END_TAG) {
if (eventType == XmlPullParser.START_TAG) {
Log.e(eventType+"", XmlPullParser.START_TAG+"");
continue;
}
String name = xpp.getName();
Log.e("out", name);
if (name.equals("CONS_REF")) {
CONS_REF = readTitle(xpp);
Log.e("CONS_REF", "i m here");
Log.e("CONS_REF", CONS_REF);
} else if (name.equals("BILL_MTH")) {
BILL_MTH = readSummary(xpp);
Log.e("BILL_MTH", "im here");
Log.e("BILL_MTH", BILL_MTH);
} else if (name.equals("NAME")) {
} else {
Log.e("skip", "i m in skip");
skip(xpp);
}
}
} catch (Exception e) {
e.printStackTrace();
//resTxt = "Error occured";
}
}
private static String readTitle(XmlPullParser parser) throws IOException, XmlPullParserException {
parser.require(XmlPullParser.START_TAG, null, "CONS_REF");
String title = readText(parser);
parser.require(XmlPullParser.END_TAG, null, "CONS_REF");
return title;
}
private static String readText(XmlPullParser parser) throws IOException, XmlPullParserException {
String result = "";
if (parser.next() == XmlPullParser.TEXT) {
result = parser.getText();
parser.nextTag();
}
return result;
}
private static void skip(XmlPullParser parser) throws XmlPullParserException, IOException {
if (parser.getEventType() != XmlPullParser.START_TAG) {
// throw new IllegalStateException();
Log.e(parser.getEventType()+"",XmlPullParser.START_TAG+" inside skip" );
}
int depth = 1;
while (depth != 0) {
switch (parser.next()) {
case XmlPullParser.END_TAG:
depth--;
break;
case XmlPullParser.START_TAG:
depth++;
break;
}
}
}
private static String readSummary(XmlPullParser parser) throws IOException, XmlPullParserException {
parser.require(XmlPullParser.START_TAG, null, "BILL_MTH");
String summary = readText(parser);
parser.require(XmlPullParser.END_TAG, null, "BILL_MTH");
return summary;
}
} }
you can do it in 2 ways 你可以用两种方式做到
with data base 与数据库
with files(i suugest better approch) 与文件(我建议更好的方法)
store as text file, keep its reference in database. 作为文本文件存储,将其引用保存在数据库中。
while accessing read its reference and then read the file. 在访问时读取其参考,然后读取文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.