Ragazzi sto cercando di prelevare il corpo di alcuni elementi in un file XML,come faccio?
Sapete aiutarmi ?
Vi posto il codice che sto usando: in pratica voglio prendere il corpo degli elementi "field name="Body" ":
Grazie anticipatamente.codice:public void startElement(String namespaceURI, String lName, // simple name (localName) String qName, // qualified name Attributes attrs) throws SAXException { if(qName.equals("field")) { if(attrs!=null) { for (int i = 0; i < attrs.getLength(); i++) { String aName = attrs.getQName(i); if(attrs.getValue(aName).equals("Body")) { System.out.println("Body trovato"); System.out.println(attrs.getValue(aName)); } } } } }
edit: ammazza, attivo questo forum -_-.
In ogni caso ho risolto, posto il codice per chi dovesse avere il mio stesso problema:
codice:public void startElement(String namespaceURI, String lName, // simple name (localName) String qName, // qualified name Attributes attrs) throws SAXException { if(qName.equals("field")) { if(attrs!=null) { for (int i = 0; i < attrs.getLength(); i++) { String aName = attrs.getQName(i); if(attrs.getValue(aName).equals("Body")) { System.out.println("INIZIO BODY"); System.out.println(attrs.getValue(aName)); body=true; } } } } } public void endElement(String namespaceURI, String sName, // simple name String qName // qualified name ) throws SAXException { if(qName.equals("field")) { System.out.println("FINE BODY"); body=false; } } public void characters(char buf[], int offset, int len) throws SAXException { if(body==true) { String ss = new String(buf,offset,len); System.out.println(ss); } /* nl(); emit("CHARS: "); String s = new String(buf, offset, len); if (!s.trim().equals("")) emit(s); */ }

Rispondi quotando