Code example for Attr

Methods: getTextContent, getValue, lookupNamespaceURI

0
     * @param attribute the attribute with a QName value 
     *  
     * @return a QName from an attributes value, or null if the given attribute is null 
     */ 
    public static QName getAttributeValueAsQName(Attr attribute) {
        if (attribute == null || DatatypeHelper.isEmpty(attribute.getValue())) {
            return null; 
        } 
 
        String attributeValue = attribute.getTextContent();
        String[] valueComponents = attributeValue.split(":");
        if (valueComponents.length == 1) {
            return constructQName(attribute.lookupNamespaceURI(null), valueComponents[0], null);
        } else { 
            return constructQName(attribute.lookupNamespaceURI(valueComponents[0]), valueComponents[1],
                    valueComponents[0]);
        } 
    } 
 
    /** 
     * Parses the attribute's value. If the value is 0 or "false" then false is returned, if the value is 1 or "true"