Bonjour ,

J'ai rencotré cette exeption et je n'ai pas compris pourquoi.

la console m'affiche
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
Current state is not among the states START_ELEMENT , ATTRIBUTEvalid for getAttributeName()
	at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.getAttributeName(Unknown Source)
DlmsObjectInformationTest :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
public class DlmsObjectInformationTest {
 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		DlmsObjectInformation dlmsObjectInformation = DlmsObjectInformation.getDlmsObjectInformationfromTask("resultTask.xml");
		System.out.println("end");
	}
 
}
la classe DlmsObjectInformation et la méthode getDlmsObjectInformationfromTask(string nameOfFile)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
public class DlmsObjectInformation {
 
	private String frameValue ;
	private String obis ;
	private String type ;
	private String attribute;
	private String classId;
	//getters setters et constructeurs 
 
public static DlmsObjectInformation getDlmsObjectInformationfromTask(String nameOfTask)
	{
		DlmsObjectInformation dlmsObjectInformation = new DlmsObjectInformation();
		XMLInputFactory factory = XMLInputFactory.newInstance();
		File file = new File(nameOfTask);
		Boolean found=false ;
		 try {
			XMLStreamReader reader = factory.createXMLStreamReader(new FileReader(file));
			 while (reader.hasNext() && !found) {
				 int type = reader.next();
				 if(type== XMLStreamReader.START_ELEMENT && reader.getLocalName().equals("dlms") )
				 {
					 found = true ;
					 int nbrOfAtt = reader.getAttributeCount();
					 String frameValue = reader.getElementText();
					 Map<String,String>  attributesValues = new HashMap<>(nbrOfAtt);
					 for(int i = 0; i <nbrOfAtt; i++)
	                  {
						 attributesValues.put(reader.getAttributeName(i).toString() , reader.getAttributeValue(i)) ;
	                  }
 
					 dlmsObjectInformation.setAttribute(attributesValues.get("attribute"));
					 dlmsObjectInformation.setClassId("classId");
					 dlmsObjectInformation.setFrameValue(frameValue);
					 dlmsObjectInformation.setObis("obis");
					 dlmsObjectInformation.setType("type");
				 }
			 }
 
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XMLStreamException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 
 
		return dlmsObjectInformation;
	}
et la fichier xml resultDataTask

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
<taskRes xmlns="xxxxx" taskId="xx" taskType="DLMS" version="2" dc="xxx">
   <target id="xxx" type="xxx">
                     <transaction association="1" type="dlms"  id="1" start="2016-06-19T19:42:28" stop="2016-06-19T19:42:29" status="done" retry="0">
    <dlms id="1" operation="getm" obis="0;0;40;0;0;255" type="ARRAY" attribute="2" classId="15" status="done"  >01230204120</dlms>
                      </transaction>
	</target>
</taskRes>
le but est de récuperer les attributs et ses valeurs de element dlms de fichier xml resultDataTask et le stocker dans dlmsObjectInformation.

merci .