4

i want to get the value of attribute of xml file without knowing it's index, since attributes are repeated in more than one element in the xml file.

here is my xml file

<fields>
  <form name="userAdditionFrom"> 
  </form>
</fields>

and here is the procssing file

 case XMLEvent.ATTRIBUTE:
      //how can i know the index of attribute?
       String attName = xmlReader.getAttributeValue(?????); 
       break;

thanx in advance.

Alaa

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
palAlaa
  • 9,500
  • 33
  • 107
  • 166

1 Answers1

5

If it is XMLStreamReader then getAttributeValue(int index) and getAttributeValue(String namespaceURI, String localName) can be used to get attribute value.

From your question it look like you are using mix of Event and Cursor API. I have appended Using StAX link for your reference that gives idea how to use both.

Resources:

  1. XMLStreamReader getAttributeValue(String, String) JavaDoc Entry
  2. Using StAX
8bitjunkie
  • 12,793
  • 9
  • 57
  • 70
Jaydeep Patel
  • 2,394
  • 1
  • 21
  • 27