,
fichier XML
Code :
- <presentationClientLog>
- <date>...</date>
- <connection>
- <system>asda</system>
- ect
- <.. ..>
- </connection>
- <ispecReceived>
- <ispecModelName>MENU</ispecModelName>
- <cursorFieldName>ACTION</cursorFieldName>
- <ispecFields>
- <... .. >
- </ispecFields>
- </ispecReceived>
- <ispecSent>
- <ispecModelName>MENU</ispecModelName>
- <cursorFieldName>ACTION</cursorFieldName>
- <ispecFields>
- <.. ..>
- </ispecFields>
- </ispecSent>
- </presentationClientLog>
|
J aimerai parser el fichier recuperer quasiment tous les fields, mettre ca entant d'attributs dobject
( exemple ObjTest = 1 objet connection (attribut x, x1, x2) + 1 Array list of ispecSent + 1 Array list of ispecReceived.
Pour ensuite reutilier les donnes (simulation de load) pour chronometrer les transactions dun serveur.
J utilise JDOM pour construre larbre en memoire et ensuite if /if else pour reconaitre les nom delement qui minteresse.
Code :
- public static void parseXML()
- {
- String caseFile = "log.xml";
- SAXBuilder builder = new SAXBuilder();
-
- // command line should offer URIs or file names
- try {
- Document document = builder.build(caseFile);
- System.out.println(caseFile + " Loaded." );
- listNodes(document);
- }
- // indicates a well-formedness error
- catch (JDOMException e) {
- System.out.println(caseFile + "XML document not well-formed." );
- System.out.println(e.getMessage());
- }
- catch (IOException e) {
- System.out.println("Could not check " + caseFile);
- System.out.println(" because " + e.getMessage());
- }
-
- }
- public static void listNodes(Object o) {
-
- if (o instanceof Element) {
- Element element = (Element) o;
- System.out.println("Element: " + element.getName());
- List children = element.getContent();
- Iterator iterator = children.iterator();
- while (iterator.hasNext()) {
- Object child = iterator.next();
- listNodes(child);
- }
- }
- else if (o instanceof Document) {
- System.out.println("Document" );
- Document doc = (Document) o;
- List children = doc.getContent();
- Iterator iterator = children.iterator();
- while (iterator.hasNext()) {
- Object child = iterator.next();
- listNodes(child);
- }
- }
- else if (o instanceof Comment) {
- System.out.println("Comment" );
- }
- else if (o instanceof CDATA) {
- System.out.println("CDATA section" );
- // CDATA is a subclass of Text so this test must come
- // before the test for Text.
- }
- else if (o instanceof Text) {
- System.out.println("Text" );
- }
- else if (o instanceof EntityRef) {
- System.out.println("Entity reference" );
- }
- else if (o instanceof ProcessingInstruction) {
- System.out.println("Processing Instruction" );
- }
- else { // This really shouldn't happen
- System.out.println("Unexpected type: " + o.getClass());
- }
-
- }
|
si je fais des test dans la fonction list genre
Code :
- if (element.getName().isEqual("system" ))
- connectionObj.setSystem = element.valeur;
|
ou encore dans le cas danstag qui se repetera
Code :
- <ispecReceived>....</ispecReceived>
- <ispecSent>....</ispecSent>
- <ispecReceived>....</ispecReceived>
- <ispecSent>....</ispecSent>
- <ispecReceived>....</ispecReceived>
- <ispecSent>....</ispecSent>
|
Code :
- if (element.getName().isEqual("ispecReceived" ))
- ajoute opjet ispecReceived + tous ses fields a ArrayList ArrayispecReceived ?;
|
voila, est ce que cest potable comme methode ?