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
|
public Map<String, Map<String, String>> traiterXMLrapportDansDossier(String unXML)
throws XMLStreamException
{
Reader stringReader = new StringReader(unXML);
XMLStreamReader reader = factory.createXMLStreamReader(stringReader);
Map<String, Map<String, String>> lesRapports = new HashMap<String, Map<String, String>>();
String tempValue;
Map<String, String> rapportData = new HashMap<String, String>();
String nom="";
while(reader.hasNext())
{
int type = reader.next();
switch (type) {
case XMLStreamConstants.START_ELEMENT:
if ("title".equals(reader.getLocalName()))
{
tempValue = reader.getElementText();
nom=tempValue;
}
if("name".equals(reader.getLocalName()))
{
tempValue = reader.getElementText();
rapportData.put(" auteur", tempValue);
}
if("attr".equals(reader.getLocalName()))
{
tempValue = reader.getAttributeValue(0); String tempValue2 = reader.getElementText();
rapportData.put(tempValue, tempValue2);
}
if(dossierInfoComplete(rapportData))
{
Map<String, String> tmp = new HashMap<String, String>();
rapportData.forEach(tmp::putIfAbsent); //Je réalise une copie de dossierData, sinon reference et clear detruit l'objet même dans le HMap
lesRapports.put(nom, tmp);
rapportData.clear();
}
break;
}
}
return lesRapports;
} |
Partager