How to get the value of processing STAX attributes using java language?

I want to get the attribute value of the xml file without knowing its index, since the 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

+3
source share
1 answer

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

From your question, it seems you are using a combination of the Event and Cursor API. I added a StAX link for your link, which gives an idea of ​​how to use both.

Resources:

+4

Source: https://habr.com/ru/post/1776820/


All Articles