code: public static String extractAttributeValue(final String attrName, final Node doc, final boolean throwException) throws XMLParsingException {
          String xpath = "descendant-or-self::*/@" + attrName;
          Nodes nodes = doc.query(xpath);
          for (int i = 0; i < nodes.size(); i++) {
              if (nodes.get(i) instanceof Attribute) {
                  return nodes.get(i).getValue();
              }
          }
          if (throwException) {
              throw new XMLParsingException("No Attribute " + attrName + " in document:\n" + doc.toXML());
          } else {
              return null;
          }
      }
docs: <p>
  Returns the first Attribute with name attrName from Document doc. Uses xPath "//
  
  @throws XMLParsingException
  @param throwException flag set throw exception if no such Attribute can be found.	<br>
  @param attrName
  @param doc
  @return