다음을 통해 공유


IXmlPullParser.NextText 메서드

정의

현재 이벤트가 START_TAG 경우 다음 요소가 TEXT이면 요소 콘텐츠가 반환되거나 다음 이벤트가 END_TAG 빈 문자열이 반환되면 예외가 throw됩니다.

[Android.Runtime.Register("nextText", "()Ljava/lang/String;", "GetNextTextHandler:Org.XmlPull.V1.IXmlPullParserInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public string? NextText ();
[<Android.Runtime.Register("nextText", "()Ljava/lang/String;", "GetNextTextHandler:Org.XmlPull.V1.IXmlPullParserInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member NextText : unit -> string

반환

특성

예외

설명

현재 이벤트가 START_TAG 경우 다음 요소가 TEXT이면 요소 콘텐츠가 반환되거나 다음 이벤트가 END_TAG 빈 문자열이 반환되면 예외가 throw됩니다. 이 함수를 성공적으로 호출하면 파서가 END_TAG 배치됩니다.

이 함수의 동기는 빈 요소와 비어있지 않은 콘텐츠가 있는 요소(예: <ol><li><)를 일관되게 구문 분석할 수 있도록 하는 것입니다. tag> foo <li>< tag> (이는 <에 해당합니다. tag/> 두 입력을 모두 동일한 코드로 구문 분석할 수 있습니다.

p.nextTag()
              p.requireEvent(p.START_TAG, "", "tag");
              String content = p.nextText();
              p.requireEvent(p.END_TAG, "", "tag");

nextTag와 함께 이 함수를 사용하면 혼합 콘텐츠가 없는 XML을 매우 쉽게 구문 분석할 수 있습니다.

기본적으로 이 작업을 수행합니다.

if(getEventType() != START_TAG) {
                throw new XmlPullParserException(
                  "parser must be on START_TAG to read next text", this, null);
             }
             int eventType = next();
             if(eventType == TEXT) {
                String result = getText();
                eventType = next();
                if(eventType != END_TAG) {
                  throw new XmlPullParserException(
                     "event TEXT it must be immediately followed by END_TAG", this, null);
                 }
                 return result;
             } else if(eventType == END_TAG) {
                return "";
             } else {
                throw new XmlPullParserException(
                  "parser must be on START_TAG or TEXT to read text", this, null);
             }

<strong>Warning:</strong> API 수준 14 이전에는 이 메서드가 호출되었을 때 반환된 android.util.Xml 끌어오기 파서가 항상 END_TAG 이벤트로 이동하지는 않았습니다. nextText()를 호출한 후 수동으로 진행하여 해결합니다.

String text = xpp.nextText();
             if (xpp.getEventType() != XmlPullParser.END_TAG) {
                 xpp.next();
             }

에 대한 org.xmlpull.v1.XmlPullParser.nextText()Java 설명서

이 페이지의 일부는 Android 오픈 소스 프로젝트에서 만들고 공유하고 Creative Commons 2.5 특성 라이선스에 설명된 용어에 따라 사용되는 작업을 기반으로 하는 수정 사항입니다.

적용 대상