mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-19 00:39:58 +00:00
Try skipping XML whitespaces more elegantly
This commit is contained in:
parent
34f44f174b
commit
f7f3c5080d
2 changed files with 19 additions and 15 deletions
|
@ -15,13 +15,28 @@ import org.xmlpull.v1.XmlPullParserException;
|
|||
*/
|
||||
public final class XmlPullUtil
|
||||
{
|
||||
|
||||
public static boolean test(final XmlPullParser pp, final String tagName) throws XmlPullParserException, IOException
|
||||
{
|
||||
if (pp.getEventType() == XmlPullParser.TEXT && pp.isWhitespace())
|
||||
pp.next();
|
||||
|
||||
return pp.getEventType() == XmlPullParser.START_TAG && pp.getName().equals(tagName);
|
||||
}
|
||||
|
||||
public static void require(final XmlPullParser pp, final String tagName) throws XmlPullParserException, IOException
|
||||
{
|
||||
if (pp.getEventType() == XmlPullParser.TEXT && pp.isWhitespace())
|
||||
pp.next();
|
||||
|
||||
pp.require(XmlPullParser.START_TAG, null, tagName);
|
||||
}
|
||||
|
||||
public static void enter(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||
{
|
||||
if (pp.getEventType() == XmlPullParser.TEXT && pp.isWhitespace())
|
||||
pp.next();
|
||||
|
||||
if (pp.getEventType() != XmlPullParser.START_TAG)
|
||||
throw new IllegalStateException("expecting start tag to enter");
|
||||
if (pp.isEmptyElementTag())
|
||||
|
@ -32,6 +47,9 @@ public final class XmlPullUtil
|
|||
|
||||
public static void enter(final XmlPullParser pp, final String tagName) throws XmlPullParserException, IOException
|
||||
{
|
||||
if (pp.getEventType() == XmlPullParser.TEXT && pp.isWhitespace())
|
||||
pp.next();
|
||||
|
||||
pp.require(XmlPullParser.START_TAG, null, tagName);
|
||||
enter(pp);
|
||||
}
|
||||
|
@ -49,6 +67,7 @@ public final class XmlPullUtil
|
|||
public static void exit(final XmlPullParser pp, final String tagName) throws XmlPullParserException, IOException
|
||||
{
|
||||
exitSkipToEnd(pp);
|
||||
|
||||
pp.require(XmlPullParser.END_TAG, null, tagName);
|
||||
pp.next();
|
||||
}
|
||||
|
@ -66,11 +85,6 @@ public final class XmlPullUtil
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean test(final XmlPullParser pp, final String tagName) throws XmlPullParserException
|
||||
{
|
||||
return pp.getEventType() == XmlPullParser.START_TAG && pp.getName().equals(tagName);
|
||||
}
|
||||
|
||||
public static void requireSkip(final XmlPullParser pp, final String tagName) throws XmlPullParserException, IOException
|
||||
{
|
||||
require(pp, tagName);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue