title: Searching for specific attribute value and text value in xml with Android
body: <p>I need to somehow find specific value in specific node and then display it in text view along with attribute value.
  <a href="http://www.bsi.si/_data/tecajnice/dtecbs-l.xml" rel="nofollow">http://www.bsi.si/_data/tecajnice/dtecbs-l.xml</a> this is the xml file i need to search, its list of exchange rates for multiple currencies. Part of the problem is also nodes that have the same name.</p>
  
  <p>I'm successfully accessing it from the web. I just could not find example or tutorial how to find specific attribute value and then using it to get desired text.
  Im working in Android Studio. Firs user will select the date of the exchange rate, then he selects desired currencies he wants to display, so it will display [Selected currency] = [Value]<br>
  So I think that if I can at least narrow the search to specific date it would be something. 
  I did this successfully before with Xpath but this file is too big, so im forced to use SAX, but im open to other examples if there is one.</p>
  
  <p>I'm using this example as a template:<a href="http://www.pcsalt.com/android/xml-parsing-using-saxparser-android/" rel="nofollow">http://www.pcsalt.com/android/xml-parsing-using-saxparser-android/</a>
  I don't know if I should use this structure, but it's the one I found most relevant to my case.</p>
  
  <p>I have some basic knowledge with java, but none with sax or any other parser.</p>
  
  <p>EDIT:</p>
  
  <p>I now have working code that returns all currencies names and exchange rates from selected date, in this example below 2007-01-01. Now I want to use user input from date picker that i have in FirstPage activity to look for exchange rates and names from that selected date, but i just can't get it to work. I don't know if it's something with the way i make string value out of 3 integers (day, month, year) or is it something with transition of this string from FirstPage activity to this XMLHelepr class. Or maybe sax won't take this variable.</p>
  
  <pre><code>public class XMLHelper extends DefaultHandler {
  /**
   * The URL to be parsed
   */
  private String URL_MAIN = "http://www.bsi.si/_data/tecajnice/dtecbs-l.xml";
  String TAG = "XMLHelper";
  String datum ;
  String oznaka;
  
  
  
  
  Boolean currTag = false;
  String currTagVal = "";
  private PostValue post = null;
  private ArrayList&lt;PostValue&gt; posts = new ArrayList&lt;PostValue&gt;();
  
  public ArrayList&lt;PostValue&gt; getPostsList() {
      return this.posts;
  }
  
  public FirstPage firstPage;
  
  
  
  public void get() {
      try {
          SAXParserFactory factory = SAXParserFactory.newInstance();
          SAXParser mSaxParser = factory.newSAXParser();
          XMLReader mXmlReader = mSaxParser.getXMLReader();
          mXmlReader.setContentHandler(this);
          InputStream mInputStream = new URL(URL_MAIN).openStream();
          mXmlReader.parse(new InputSource(mInputStream));
      } catch (Exception e) {
          // Exceptions can be handled for different types
          // But, this is about XML Parsing not about Exception Handling
          Log.e(TAG, "Exception: " + e.getMessage());
      }
  }
  
  
  @Override
  public void startElement(String uri, String localName, String qName,
                           Attributes attributes) throws SAXException {
      Log.i(TAG, "TAG: " + localName);
  
      currTag = true;
      currTagVal = "";
  
      int len = attributes.getLength();
      // Loop through all attributes and save them as needed
      for(int i = 0; i &lt; len; i++)
      {
          String sAttrName = attributes.getLocalName(i);
          if(sAttrName.compareTo("datum") == 0)
          {
  
              datum = attributes.getValue(i);
              Log.i(TAG, "Datum: " + datum);
          }
      }
      int len2 = attributes.getLength();
      // Loop through all attributes and save them as needed
      for(int i = 0; i &lt; len2; i++){
          String sAttrName = attributes.getLocalName(i);
          if(sAttrName.compareTo("oznaka") == 0)
          {
  
              oznaka = attributes.getValue(i);
              Log.i(TAG, "Oznaka: " + oznaka);
          }
  
      }
  
  
  
  
  }
  
  
  
  @Override
  public void characters(char[] ch, int start, int length)
          throws SAXException {
      if(datum.equals("2007-01-01")){
  
      if(oznaka.equals(oznaka)) {
          post = new PostValue();
          if (currTag) {
              currTagVal = currTagVal + new String(ch, start, length);
              currTag = false;
              post.setOznaka(oznaka);
              post.setVrednost(currTagVal);
          }
      }
      }
  }
  
  
  @Override
  public void endElement(String uri, String localName, String qName)
          throws SAXException {
      currTag = false;
      if(currTagVal!="")
          posts.add(post);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>im using date picker on FirstPage activity and geting values into String to use it to compere with attribute "datum" from XMLHelper.Im seting izbraniDatum value with geter-setter in this activity, and it displays correct on the textview in first activity</p>
  
  <pre><code>dp1 = new DatePickerDialog.OnDateSetListener() {
          @Override
          public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
              leto1= year;
              mesec1= monthOfYear +1;
              dan1 = dayOfMonth;
              izbraniDatum= checkDigit(year)+"-"+checkDigit(monthOfYear + 1)+"-"+checkDigit(dayOfMonth);
              setIzbraniDatum(izbraniDatum);
              prikaz1.setText(getIzbraniDatum());
          }
      };
  </code></pre>
  
  <p>and the comparing line in XMLHelper:</p>
  
  <pre><code>@Override
  public void characters(char[] ch, int start, int length)
          throws SAXException {
      if(datum.equals(firstPage.getIzbraniDatum())){
  </code></pre>
  
  <p>anyone help?</p>