本文整理汇总了Java中org.codehaus.plexus.util.xml.pull.MXParser类的典型用法代码示例。如果您正苦于以下问题:Java MXParser类的具体用法?Java MXParser怎么用?Java MXParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MXParser类属于org.codehaus.plexus.util.xml.pull包,在下文中一共展示了MXParser类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseXml
import org.codehaus.plexus.util.xml.pull.MXParser; //导入依赖的package包/类
public static Difference[] parseXml( Reader xml )
throws XmlPullParserException, IOException
{
XmlPullParser parser = new MXParser();
parser.setInput( xml );
List<Difference> diffs = new ArrayList<Difference>();
int state = 0;
int event;
Difference current = null;
while ( ( event = parser.next() ) != XmlPullParser.END_DOCUMENT )
{
switch ( event )
{
case XmlPullParser.START_TAG:
switch ( state )
{
case 0: // start document
state = 1;
break;
case 1: // expect next difference
if ( "difference".equals( parser.getName() ) )
{
current = new Difference();
state = 2;
}
break;
case 2: // reading difference
String name = parser.getName();
String value = parser.nextText().trim();
if ( "className".equals( name ) )
{
current.className = value;
}
else if ( "differenceType".equals( name ) )
{
current.differenceType = Integer.parseInt( value );
}
else if ( "field".equals( name ) )
{
current.field = value;
}
else if ( "method".equals( name ) )
{
current.method = value;
}
else if ( "from".equals( name ) )
{
current.from = value;
}
else if ( "to".equals( name ) )
{
current.to = value;
}
else if ( "justification".equals( name ) )
{
current.justification = value;
}
break;
}
break;
case XmlPullParser.END_TAG:
switch ( state )
{
case 1:
case 2:
if ( "difference".equals( parser.getName() ) )
{
diffs.add( current );
state = 1;
}
break;
}
}
}
return diffs.toArray( new Difference[diffs.size()] );
}
示例2: State
import org.codehaus.plexus.util.xml.pull.MXParser; //导入依赖的package包/类
State(URL url) throws XMLParserException {
parser = new MXParser();
this.url = url;
try {
parser.setInput(url.openStream(), null);
} catch (XmlPullParserException xmlppe) {
throw new XMLParserException("XML document malformed", xmlppe);
} catch (IOException ioe) {
throw new XMLParserException(
"I/O error when accessing XML document: " + url, ioe);
}
}