Originally Posted by
DemeCarv
Piece of XSL:
<?xml version="1.0" encoding="UTF-8"?>
<c:message xmlns:c="ictt"><c:de format="B" lengthField="0" name="BIT MAP, PRIMARY" number="000"/><c:de format="B" lengthField="0" maxLength="008" minLength="008" name="BIT MAP, SECONDARY" number="001" subFields="00"/>
Piece of Java Code:
int length = Integer.parseInt(spec.getAttribute("maxLength"));
maxLength is an attribute of the
c:de element, and the above call (where
spec is an
Element object) is the correct call to do this. However from the XML (not XSL) fragment above you'd see that the first
c:de element does not have the
maxLength attribute. Also, the image you attached to your post is too small to make out what
spec is. (Btw, please paste your code into your post as
text, wrapped in [code] tags, and
not as a screenshot.)
Originally Posted by
DemeCarv
[5/13/14 14:52:19:497 CDT] 00000028 SystemErr R java.lang.NumberFormatException: For input string: ""
What we know from the exception message that the call to
getAttribute() returned an empty string. The
API doc for this method states,
"Returns:
The Attr value as a string, or the empty string if that attribute does not have a specified or default value."
Therefore it is possible that
spec is referring to an element that does not have the
maxLength attribute, just like the first
c:de element.
You can confirm this by using
hasAttribute(String name), or by printing out the element, e.g., via an identity transform:
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(spec), new StreamResult(System.out));
If you're still unable to solve this problem, we'll need more than the 1 line of code and a tiny screenshot.