第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

為什么我的setId報(bào)錯(cuò)


package handler;


import java.awt.print.Book;


import org.xml.sax.Attributes;

import org.xml.sax.SAXException;

import org.xml.sax.helpers.DefaultHandler;


public class SAXParserHandler extends DefaultHandler {

int bookIndex = 0;

? ? /*

? ? ?*用來標(biāo)識(shí)解析開始?

? ? ?*/

? ? @Override

? ? public void startDocument() throws SAXException {

? ? super.startDocument();

? ? System.out.println("SAX解析開始");

? ? }

? ? /*

? ? ?*用來標(biāo)識(shí)解析開始?

? ? ?*/

? ? @Override

? ? public void endDocument() throws SAXException {

? ? super.endDocument();

? ? System.out.println("SAX解析結(jié)束");

? ? }

? ? /*

? ? ?*解析xml元素?

? ? ?*/

? ? @Override

? ? public void startElement(String uri, String localName, String qName,

? ? Attributes attributes) throws SAXException {

? ? // 調(diào)用DefaultHandler類的startElement方法

? ? super.startElement(uri, localName, qName, attributes);

? ? //開始解析book元素的屬性

? ? if (qName.equals("book")){

? ? bookIndex++;

? ? ? Book book = new Book();

? ? System.out.println("===================下面開始遍歷第"+bookIndex+"本書的內(nèi)容===================");

// ? ? ? ? ? String value = attributes.getValue("id");

// ? ? System.out.println("book的屬性值是:" + value);

? ? int num = attributes.getLength();

? ? for (int i = 0;i < num;i++){

? ? System.out.print("book元素的第"+(i+1)+"個(gè)屬性名是"

? ? ? ? ? ? ?+attributes.getQName(i));

? ? System.out.println("---屬性值是:"+attributes.getValue(i));

? ? if (attributes.getQName(i).equals("id")){

? ? book.setId(attributes.getValue(i));

? ? }

? ? }

? ? }

? ? else if (!qName.equals("book") && !qName.equals("bookstore")){

? ? System.out.print("節(jié)點(diǎn)名是:"+qName);

? ? }

? ? }

? ??

? ? @Override

? ? public void endElement(String uri, String localName, String qName) throws SAXException {

? ? // 調(diào)用DefaultHandler類的endElement方法?

? ? super.endElement(uri, localName, qName);

? ? //判斷是否針對一本書已經(jīng)遍歷結(jié)束

? ? if (qName.equals("book")){

System.out.println("===================結(jié)束遍歷第"+bookIndex+"本書的內(nèi)容===================");

? ? }

? ? }

? ??

? ? @Override

? ? public void characters(char[] ch, int start, int length) throws SAXException {

? ? // TODO 自動(dòng)生成的方法存根

? ? super.characters(ch, start, length);

? ? String value = new String(ch, start, length);

? ? if(!value.trim().equals("")){

? ? System.out.println("---節(jié)點(diǎn)值是:"+value);

? ? }

? ? }

? ??

}



正在回答

1 回答

多了一個(gè)book的導(dǎo)入

1 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么我的setId報(bào)錯(cuò)

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)