get Int Element from StartElement in StAX parser - Java XML

Java examples for XML:DOM Element

Description

get Int Element from StartElement in StAX parser

Demo Code


//package com.java2s;

import javax.xml.namespace.QName;

import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.StartElement;

public class Main {
    public static int getIntElement(StartElement startElement,
            String elementName) {
        int parent = 0;
        Attribute parentIdAttr = startElement.getAttributeByName(new QName(
                elementName));//w w w.ja  v  a 2 s .  co  m
        if (parentIdAttr != null) {
            parent = Integer.parseInt(parentIdAttr.getValue());
        }
        return parent;
    }
}

Related Tutorials