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

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

@JaydeepPatel Are indexes counted from 0 or from 1?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.