0

私のxml文字列は次のようになります:

<facebookfriends>
    <data>
        <id> 501334283</id>
        <location>
            <id>46464 </id>
            <name>abc </name>
        </location>
        <name> Name Something</name>
        <education>
            <school>
                <id> 45454 </id>
                <name> SSSSSSSSSS</name>
            </school>
            <year>
                <id> 45353</id>
                <name> 2001</name>
            </year>
            <type>High School </type>
        </education>
        <education>
            <school>
                <id>
                    134960646529265</id>
                <name> SSS , University</name>
            </school>
            <year>
                <id> 132393000129123</id>
                <name> 2001</name>
            </year>
            <type>High School </type>
        </education>
        <education>
            <concentration>
                <id> 6868</id>
                <name> Computer Science and Engineering
                </name>
            </concentration>
            <school>
                <id> 86868</id>
                <name>
                    Hellio
                </name>
            </school>
            <year>
                <id> 4646</id>
                <name> 2008</name>
            </year>
            <type>College </type>
        </education>

    </data>
    <data>XYZ</data>
</facebookfriends>

教育リストは学校名を意味します。私の要件は次のようなものです。最初のデータタグの開始とデータタグの終了、次に2番目のデータタグの開始、データタグの終了、3番目などから教育の詳細のリストを取得します。だから私はこのように試しましたが、データを取得できません。

    StringReader reader = new StringReader(xmlbody);//XML body is my xml string
    InputSource source = new InputSource(reader);
    Document document = dbBuilder.parse(source);
    NodeList dataList = document.getElementsByTagName("data");
        for(int i=0;i<dataList.getLength();i++) {
            Node node = dataList.item(i);
            if(node.getNodeType() == Node.ELEMENT_NODE) {
                Element data = (Element)node;

        org.jsoup.nodes.Document xmlDoc = Jsoup.parse(data.getTextContent(), "", Parser.xmlParser());

                    for (org.jsoup.nodes.Element e : xmlDoc.select("education")) {
                        System.out.println(e);
                    }

            }
                           }

期待される出力: 取得したい最初の反復で: SSSSSSSSSS 、 SSS 、 University 、Hellio

助けてください

4

1 に答える 1