亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

關于handle中重寫startElement()方法中的參數問題

startElement(String uri, String localName, String qName,

Attributes attributes)中的參數在哪里傳入handle對象的呀?主函數里新建了一個handle對象,也沒傳參數呀?尤其這個localName參數,都沒有見到呀,或者是parse()函數傳來的?


正在回答

3 回答

我感覺這個startElement方法應該是JAVA官方類的源代碼中的方法,只有用法。當你主函數調用parse(uri,dh)時,parse方法就已經把xml文件進行解析,并且獲取了你問題里的參數,這都是官方類的操作,我們看不到的。

1 回復 有任何疑惑可以回復我~
#1

0110號建筑師 提問者

非常感謝!
2017-06-05 回復 有任何疑惑可以回復我~

請注意看參數

0 回復 有任何疑惑可以回復我~

SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();

SAXParser saxParser = saxParserFactory.newSAXParser();

SaxParserHandler saxParserHandler = new SaxParserHandler();

saxParser.parse("books.xml", saxParserHandler);

//parse()?

public void parse(String uri, DefaultHandler dh)

? ? ? ? throws SAXException, IOException {

? ? ? ? if (uri == null) {

? ? ? ? ? ? throw new IllegalArgumentException("uri cannot be null");

? ? ? ? }


? ? ? ? InputSource input = new InputSource(uri);

? ? ? ? this.parse(input, dh);//------------執行到此處

? ? }


public void parse(InputSource is, DefaultHandler dh)

? ? ? ? throws SAXException, IOException {

? ? ? ? if (is == null) {

? ? ? ? ? ? throw new IllegalArgumentException("InputSource cannot be null");

? ? ? ? }


? ? ? ? XMLReader reader = this.getXMLReader();

? ? ? ? if (dh != null) {

? ? ? ? ? ? reader.setContentHandler(dh);

? ? ? ? ? ? reader.setEntityResolver(dh);

? ? ? ? ? ? reader.setErrorHandler(dh);

? ? ? ? ? ? reader.setDTDHandler(dh);

? ? ? ? }

? ? ? ? reader.parse(is);//----------

? ? }


?public void parse (InputSource input)

? ? ? ? throws IOException, SAXException;

//----------

void org.xml.sax.XMLReader





?/**

? ? ?* Receive notification of the start of an element.

? ? ?*

? ? ?* <p>By default, do nothing.? Application writers may override this

? ? ?* method in a subclass to take specific actions at the start of

? ? ?* each element (such as allocating a new tree node or writing

? ? ?* output to a file).</p>

? ? ?*

? ? ?* @param uri The Namespace URI, or the empty string if the

? ? ?*? ? ? ? element has no Namespace URI or if Namespace

? ? ?*? ? ? ? processing is not being performed.

? ? ?* @param localName The local name (without prefix), or the

? ? ?*? ? ? ? empty string if Namespace processing is not being

? ? ?*? ? ? ? performed.

? ? ?* @param qName The qualified name (with prefix), or the

? ? ?*? ? ? ? empty string if qualified names are not available.

? ? ?* @param attributes The attributes attached to the element.? If

? ? ?*? ? ? ? there are no attributes, it shall be an empty

? ? ?*? ? ? ? Attributes object.

? ? ?* @exception org.xml.sax.SAXException Any SAX exception, possibly

? ? ?*? ? ? ? ? ? wrapping another exception.

? ? ?* @see org.xml.sax.ContentHandler#startElement

? ? ?*/

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

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? String qName, Attributes attributes)

? ? ? ? throws SAXException

? ? {

? ? ? ? // no op

? ? }


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

關于handle中重寫startElement()方法中的參數問題

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號