Beispiel #1
0
        /**
         * "Parse" an XML document for the first occurrence of a particular tag and return its value, which is assumed to be a number.
         *
         * The parse terminates based on the rules for java.text.DecimalFormat, using the
         * pattern and symbol sets for the default Locale.
         *
         * @param xmlDoc
         *  The target XML document.
         * @param xmlTag
         *  The target tag <em>including</em> the enclosing angle brackets.
         * @param xmlStart
         *  The character position (from zero) in the document at which to start
         *  looking for the target tag.
         *
         * @return
         *  <ul>
         *      <li>an integer representation of the element value</li>
         *      <li>-1 if:
         *          <ul>
         *              <li>not found</li>
         *              <li>the target tag is empty, for example, <code>&lt;part&gt;&lt;/part&gt;</code></li>
         *              <li>a parse error occurred</li>
         *          </ul>
         *      </li>
         *  </ul>
         *
         * @since 1.0
         */
        public int getXmlValueNum(String xmlDoc, String xmlTag, ParsePosition xmlStart)
        {
            if (verboseDebugLvl)
            {
                MySession.myConsole.printf("%s.getXmlValueNum: xmlDoc =%n%s%nxmlTag = %s%nstartIdx = %d%n",
                                           MY_CLASS_TAG, xmlDoc, xmlTag, xmlStart.getIndex());
            }

            parseFmt.setParseBigDecimal(false);
            parsePos.setErrorIndex(-1);

            int i = xmlDoc.IndexOf(xmlTag, xmlStart.getIndex());

            if (i != -1)
            {
                parsePos.setIndex((i + xmlTag.Length));
                if ((parseResult = parseFmt.parse(xmlDoc, parsePos)) != null)
                {
                    return(parseResult.intValue());
                }
            }
            return(-1);
        }