1

こんにちは、sax パーサーを使用して html データを含む xml からデータを解析しようとしています。xml のデータは以下のようになります。

しかし、解析中に詳細タグ間のデータを異なる文字列として取得していますが、詳細タグ間の完全な 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>

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;
    }
}
}
4

0 に答える 0