XML Attribute auslesen mit JAVA

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • XML Attribute auslesen mit JAVA

    hey,...

    mein Problem ist folgendes:
    Ich will aus einer XML Datei bestimmte Inhalte auslesen...
    und zwar nur die, die das Attribut "type = test " haben..

    public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    if( attrs != null )
    {
    for( int i=0; i<attrs.getLength(); i++ )
    {
    String aName = attrs.getLocalName( i ); // Attr name
    if( "".equals( aName ) ) aName = attrs.getQName( i );
    String aVal = attrs.getValue(i);
    if( "".equals( aVal ) ) aVal = attrs.getValue(i);
    System.out.println(aVal + " "+aName);

    if(aName =="type" && aVal=="test" ){
    if(qName.equals("Name")){
    this.author = true;}
    if(qName.equals("Age")){
    this.titel = true; }
    }
    }
    }
    }

    aVal und aName werden auch ausgegeben und die stimmen auch....
    Fehler liegt irgendiwie bei if abfrage....

    Habt ihr eine idee???

    Danke !

    gruß

    YAT
    Last edited by YAT; 30-01-2009, 08:42.

  • #2
    hat sich erledigt...... xD

    hab statt
    if(aName =="type" && aVal=="test" )

    if(aName.equals("type") && aVal.equals("test") )
    benutzt so funktioniert des ganze...

    XD

    Comment

    Working...
    X