1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.car.scalableui.loader.xml; 18 19 import org.xmlpull.v1.XmlPullParser; 20 import org.xmlpull.v1.XmlPullParserException; 21 22 import java.io.IOException; 23 24 /** 25 * This class provides helper methods for working with XmlPullParser. 26 */ 27 public class XmlPullParserHelper { 28 /** 29 * Skips an XML tag and all its contents. 30 * 31 * @param parser The XML parser. 32 * @throws XmlPullParserException If an error occurs during XML parsing. 33 * @throws IOException If an I/O error occurs while reading the XML. 34 */ skip(XmlPullParser parser)35 static void skip(XmlPullParser parser) throws XmlPullParserException, IOException { 36 if (parser.getEventType() != XmlPullParser.START_TAG) throw new IllegalStateException(); 37 int depth = 1; 38 while (depth != 0) { 39 switch (parser.next()) { 40 case XmlPullParser.END_TAG: 41 depth--; 42 break; 43 case XmlPullParser.START_TAG: 44 depth++; 45 break; 46 } 47 } 48 } 49 } 50