tags:

views:

128

answers:

2

I'm using SAX to parse some XML. In my handler's startElement() method I'm trying to read the value of an attribute named xsi:type with something like:

String type = attributes.getValue("xsi:type");

However, it always returns null. This works fine for everything else so I'm assuming that it's due to the namespace prefix. How can I get this value?

+2  A: 

Probably this can help, try to play a little with this. This will return the names and the value of the attributes found which can be useful to find the name to use to query.

if (attributes.getLength() > 0) {
  for (int i = 0; i < attributes.getLength(); i++) {
    System.out.print  ("name: " + attributes.getQName(i)));
    System.out.println(" value: " + attributes.getValue(i)));  
  }
}

Take also a look here and here check the function: getURI

dawez
+1  A: 

Try asking SAX what it thinks the attribute's qName is:

for (int i=0; i < attributes.getLength(); i++) {
    String qName = attributes.getQName(i);
    System.out.println("qName for position " + i + ":  " + qName);
}
Drew Wills