Android XMLPullParser无法解析具有javaScript函数的Html String,其中使用小于符号作为if条件。 还有其他任何建议......!
String webContent = "........";
XmlPullParserFactory xmlFactoryObject = XmlPullParserFactory.newInstance();
XmlPullParser myParser = xmlFactoryObject.newPullParser();
InputStream is = new ByteArrayInputStream( webContent.getBytes( "utf-8" ) );
myParser.setInput(is, null);
int event = myParser.getEventType();
String tableData = "";
while (event != XmlPullParser.END_DOCUMENT)
{
String name=myParser.getName();
Log.e(TAG, "The event name is : "+name);
switch (event){
case XmlPullParser.START_TAG:
if(name.equals("table")){
tableData = myParser.getText();
}
break;
case XmlPullParser.END_TAG:
break;
}
Log.e(TAG, "the text for tag "+name+" is "+myParser.getText());
event = myParser.next();
}
当它试图解析脚本标记的以下字符串时,myparser.getText()将文本返回到'<'如果条件符号但不符合脚本的结束标记
<script type="text/javascript">
jQuery(document).ready(function($) {
var txt = $("p#crt").html().replace((/[A-Za-z]|(\W)/g),"")
if(txt < 1) {txt = 0};
$("#crtnumber").html(txt)
if( txt == 1 ) {$("#crttext").html(" item")}
else {$("#crttext").html(" items")}
$("p#crt").remove()
});
</script>