Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取html数据时出现Android sax解析器错误_Java_Android_Xml Parsing_Saxparser - Fatal编程技术网

Java 获取html数据时出现Android sax解析器错误

Java 获取html数据时出现Android sax解析器错误,java,android,xml-parsing,saxparser,Java,Android,Xml Parsing,Saxparser,您好,我正在尝试使用sax解析器从包含html数据的xml解析数据。xml中的数据如下所示 但在解析时,我将details标记之间的数据作为不同的字符串获取,而不是作为单个字符串获取,该字符串包含dtails标记之间的完整html数据 有谁能帮我解决这个问题吗 <details> <html> <b>Animal Care BTEC Level 1</b> <hr style="height:0.03em;width

您好,我正在尝试使用sax解析器从包含html数据的xml解析数据。xml中的数据如下所示

但在解析时,我将details标记之间的数据作为不同的字符串获取,而不是作为单个字符串获取,该字符串包含dtails标记之间的完整html数据

有谁能帮我解决这个问题吗

<details>
    <html> <b>Animal Care BTEC Level 1</b>

        <hr style="height:0.03em;width:18em;border:1px ;border-style:dotted;margin-left:0; color:white"
        />

        <body>
            <e>Course Length: 1 year</e>
            <br />
            <e>Fees: Free for 16-18 year olds</e>
            <br />
            <e>Course Code: B332</e>
            <br />
            <br />

            <body> <b> Overview:</b>

                <hr style="height:0.03em;width:18em;border:1px ;border-style:dotted;margin-left:0 ;color:white"
                />
                <p>The course provides a basic introduction to working with animals. A practical
                    approach allows student to develop animal handling skills along side personal
                    and social development. Student will have access to a wide range of animals
                    to enable them to develop skills and confidence. Each week practical work
                    will include time spent on the animal unit, the farm and at the equine
                    centre to enable students to develop practical ability in all three areas.</p>
            </body>

    </html>
</details>

动物护理BTEC 1级

课程长度:1年
费用:16-18岁免费
课程代码:B332

概述:
本课程提供了与动物合作的基本介绍。实用的 该方法允许学生在个人训练的同时发展动物处理技能 和社会发展。学生可以接触到各种各样的动物 使他们能够培养技能和信心。每周都有实际工作 将包括花在动物单位、农场和马上的时间 该中心旨在培养学生在这三个领域的实践能力


package com.bb.mypotential;
导入java.util.ArrayList;
导入org.xml.sax.Attributes;
导入org.xml.sax.SAXException;
导入org.xml.sax.helpers.DefaultHandler;
导入android.util.Log;
公共类SaxHandler扩展了DefaultHandler{
公共静态Courseobj Courseobj;
公共静态主体;
公共布尔值courseidb=false;
公共布尔coursesubjectb=false;
公共布尔CourseTleb=false;
公共布尔主语db=false;
公共布尔subjectnameb=false;
公共布尔subjectcodeb=false;
公共布尔subjectdetailsb=false;
公共布尔值entryRequirementb=false;
公共布尔coursecontb=false;
公共布尔值futhuroptionsb=false;
public boolean additionalInfob=false;
公共布尔fundingfob=false;
公共布尔赋值方法b=false;
公共字符串currentvalue=null;
公共ArrayList subar=null;
字符串标记=getClass().getSimpleName();
@凌驾
public void startElement(字符串uri、字符串localName、字符串qName、,
属性)引发SAX异常{
//TODO自动生成的方法存根
if(localName.equals(“课程”)){
MainListActivity.value=新的ArrayList();
}
if(localName.equals(“课程”)){
courseobj=新courseobj();
subar=newarraylist();
字符串courseid=attributes.getValue(0);//getValue(“ID”);
courseobj.setCOURSE_ID(courseid);
courseidb=true;
}else if(localName.equalsIgnoreCase(“title”)){
CourseTileb=true;
}else if(localName.equals(“subject”)){
subjectobj=新主题();
String subid=attributes.getValue(0);
subjectobj.setSUB_ID(subid);
主观性db=真;
}else if(localName.equals(“name”)){
subjectnameb=true;
}else if(localName.equals(“代码”)){
subjectcodeb=true;
}else if(localName.equals(“详细信息”)){
subjectdetailsb=真;
}else if(localName.equals(“entryRequirement”)){
entryRequirementb=真;
}else if(localName.equals(“courseContent”)){
CourseContB=true;
}else if(localName.equals(“assignmentMethods”)){
赋值方法b=真;
}else if(localName.equals(“进一步选项”)){
futhuroptionsb=真;
}else if(localName.equals(“附加信息”)){
additionalInfob=true;
}else if(localName.equals(“fundingInformation”)){
fundingfob=真;
}
}
@凌驾
公共无效字符(字符[]ch,整数开始,整数长度)
抛出SAX异常{
//TODO自动生成的方法存根
currentvalue=新字符串(ch、开始、长度);
if(CourseTileb){
courseobj.setTitle(当前值);
}else if(subjectnameb){
subjectobj.setName(当前值);
}否则如果(主题代码B){
subjectobj.setCode(当前值);
}else if(subjectdetailsb){
subjectobj.setDetails(当前值);
}else if(入口要求B){
subjectobj.setEntryRequirement(当前值);
}else if(课程内容B){
subjectobj.setCourseContent(当前值);
}否则,如果(b){
subjectobj.setCourseContent(当前值);
}其他如果(未来选项B){
subjectobj.setFuthuroptions(当前值);
}else if(附加信息B){
subjectobj.setAdditionalInfo(当前值);
}其他如果(FOB){
subjectobj.setFundingInfo(当前值);
}
}
@凌驾
公共void endElement(字符串uri、字符串localName、字符串qName)
抛出SAX异常{
//TODO自动生成的方法存根
if(localName.equalsIgnoreCase(“课程”)){
courseobj.setSubject(Subar);
MainListActivity.value.add(courseobj);
courseidb=false;
}else if(localName.equalsIgnoreCase(“title”)){
CourseTileb=false;
}else if(localName.equals(“subject”)){
子目录添加(subjectobj);
主观性b=假;
}else if(localName.equals(“name”)){
subjectnameb=false;
}else if(localName.equals(“代码”)){
subjectcodeb=false;
}else if(localName.equals(“详细信息”)){
subjectdetailsb=假;
}else if(localName.equals(“entryRequirement”)){
entryRequirementb=假;
}else if(localName.equals(“courseContent”)){
courseContentb=false;
}else if(localName.equals(“assignmentMethods”)){
赋值方法b=假;
}否则
package com.bb.mypotential;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;

public class SaxHandler extends DefaultHandler {
    public static Courseobj courseobj;
    public static Subject subjectobj;
    public boolean courseidb = false;
    public boolean coursesubjectb = false;
    public boolean coursetitleb = false;
    public boolean subjectidb = false;
    public boolean subjectnameb = false;
    public boolean subjectcodeb = false;
    public boolean subjectdetailsb = false;
    public boolean entryRequirementb = false;
    public boolean courseContentb = false;
    public boolean futhuroptionsb = false;
    public boolean additionalInfob = false;
    public boolean fundingInfob = false;
    public boolean assignmethodb = false;


public String currentvalue = null;
public ArrayList<Subject> subarr = null;

String TAG = getClass().getSimpleName();

@Override
public void startElement(String uri, String localName, String qName,
        Attributes attributes) throws SAXException {
    // TODO Auto-generated method stub
    if (localName.equals("Courses")) {
        MainListActivity.value = new ArrayList<Courseobj>();
    }
    if (localName.equals("Course")) {
        courseobj = new Courseobj();
        subarr = new ArrayList<Subject>();
        String courseid = attributes.getValue(0);// getValue("ID");
        courseobj.setCOURSE_ID(courseid);
        courseidb = true;
    } else if (localName.equalsIgnoreCase("title")) {
        coursetitleb = true;

    } else if (localName.equals("subject")) {
        subjectobj = new Subject();
        String subid = attributes.getValue(0);
        subjectobj.setSUB_ID(subid);

        subjectidb = true;
    } else if (localName.equals("name")) {
        subjectnameb = true;

    } else if (localName.equals("code")) {
        subjectcodeb = true;
    } else if (localName.equals("details")) {
        subjectdetailsb = true;
    } else if (localName.equals("entryRequirement")) {
        entryRequirementb = true;
    } else if (localName.equals("courseContent")) {
        courseContentb = true;
    } else if (localName.equals("assignmentMethods")) {
        assignmethodb = true;
    } else if (localName.equals("furtherOptions")) {
        futhuroptionsb = true;
    } else if (localName.equals("additionalInformation")) {
        additionalInfob = true;
    } else if (localName.equals("fundingInformation")) {
        fundingInfob = true;
    }

}

@Override
public void characters(char[] ch, int start, int length)
        throws SAXException {
    // TODO Auto-generated method stub

    currentvalue = new String(ch, start, length);

    if (coursetitleb) {
        courseobj.setTitle(currentvalue);

    } else if (subjectnameb) {
        subjectobj.setName(currentvalue);


    } else if (subjectcodeb) {
        subjectobj.setCode(currentvalue);

    } else if (subjectdetailsb) {
        subjectobj.setDetails(currentvalue);

    } else if (entryRequirementb) {
        subjectobj.setEntryRequirement(currentvalue);
    } else if (courseContentb) {
        subjectobj.setCourseContent(currentvalue);
    } else if (assignmethodb) {
        subjectobj.setCourseContent(currentvalue);
    } else if (futhuroptionsb) {
        subjectobj.setFuthuroptions(currentvalue);
    } else if (additionalInfob) {
        subjectobj.setAdditionalInfo(currentvalue);
    } else if (fundingInfob) {
        subjectobj.setFundingInfo(currentvalue);
    }

}

@Override
public void endElement(String uri, String localName, String qName)
        throws SAXException {
    // TODO Auto-generated method stub
    if (localName.equalsIgnoreCase("Course")) {

        courseobj.setSubject(subarr);
        MainListActivity.value.add(courseobj);

        courseidb = false;
    } else if (localName.equalsIgnoreCase("title")) {
        coursetitleb = false;
    } else if (localName.equals("subject")) {

        subarr.add(subjectobj);
        subjectidb = false;

    } else if (localName.equals("name")) {
        subjectnameb = false;

    } else if (localName.equals("code")) {
        subjectcodeb = false;
    } else if (localName.equals("details")) {
        subjectdetailsb = false;
    } else if (localName.equals("entryRequirement")) {
        entryRequirementb = false;
    } else if (localName.equals("courseContent")) {
        courseContentb = false;
    } else if (localName.equals("assignmentMethods")) {
        assignmethodb = false;
    } else if (localName.equals("furtherOptions")) {
        futhuroptionsb = false;
    } else if (localName.equals("additionalInformation")) {
        additionalInfob = false;
    } else if (localName.equals("fundingInformation")) {
        fundingInfob = false;
    }
}
}