From 5a5bd040ce93c7b1ba3efaf64df6c1e5849fb1a9 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sun, 7 May 2017 16:24:37 +0200 Subject: [PATCH] Refactored foo code. --- src/fr/devinsy/util/xml/XMLReader.java | 73 ------------------ test/foo/Foo.java | 103 +++++++++++++++++++++++++ test/foo/foo.xml | 40 ++++++++++ 3 files changed, 143 insertions(+), 73 deletions(-) create mode 100644 test/foo/Foo.java create mode 100644 test/foo/foo.xml diff --git a/src/fr/devinsy/util/xml/XMLReader.java b/src/fr/devinsy/util/xml/XMLReader.java index 541f032..58253d6 100644 --- a/src/fr/devinsy/util/xml/XMLReader.java +++ b/src/fr/devinsy/util/xml/XMLReader.java @@ -586,77 +586,4 @@ public class XMLReader // return result; } - - /** - * The main method. - * - * @param args - * the arguments - * @throws Exception - * the exception - */ - public static void main(final String args[]) throws Exception - { - - XMLInputFactory factory = XMLInputFactory.newInstance(); - XMLEventReader in = factory.createXMLEventReader(new FileReader("/home/cpm/C/Puck/Dev/Puck/test/TT/t3.puc")); - - XMLEvent event; - while (in.hasNext()) - { - event = in.nextEvent(); - - switch (event.getEventType()) - { - case XMLEvent.ATTRIBUTE: - System.out.println("ATTRIBUTE "); - break; - case XMLEvent.CDATA: - System.out.println("CDATA"); - break; - case XMLEvent.CHARACTERS: - System.out.println("CHARACTERS [" + event.asCharacters().getData() + "]"); - break; - case XMLEvent.COMMENT: - System.out.println("COMMENT"); - break; - case XMLEvent.DTD: - System.out.println("DTD"); - break; - case XMLEvent.END_DOCUMENT: - System.out.println("END_DOCUMENT"); - break; - case XMLEvent.END_ELEMENT: - System.out.println("END_ELEMENT " + event.asEndElement().getName()); - break; - case XMLEvent.ENTITY_DECLARATION: - System.out.println("ENTITY_DECLARATION"); - break; - case XMLEvent.ENTITY_REFERENCE: - System.out.println("ENTITY_REFERENCE"); - break; - case XMLEvent.NAMESPACE: - System.out.println("NAMESPACE"); - break; - case XMLEvent.NOTATION_DECLARATION: - System.out.println("NOTATION_DECLARATION"); - break; - case XMLEvent.PROCESSING_INSTRUCTION: - System.out.println("PROCESSING_INSTRUCTION"); - break; - case XMLEvent.SPACE: - System.out.println("SPACE"); - break; - case XMLEvent.START_DOCUMENT: - System.out.println("START_DOCUMENT"); - break; - case XMLEvent.START_ELEMENT: - System.out.println("START_ELEMENT [name=" + event.asStartElement().getName() + "][namespaceURI=" + event.asStartElement().getName().getNamespaceURI() + "][prefix=" - + event.asStartElement().getName().getPrefix() + "][localPart=" + event.asStartElement().getName().getLocalPart() + "]"); - break; - default: - System.out.println("DEFAULT"); - } - } - } } diff --git a/test/foo/Foo.java b/test/foo/Foo.java new file mode 100644 index 0000000..652efbf --- /dev/null +++ b/test/foo/Foo.java @@ -0,0 +1,103 @@ +package foo; + +/* + * Copyright (C) 2013-2014,2017 Christian Pierre MOMON + * + * This file is part of Devinsy-xml. + * + * Devinsy-xml is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Devinsy-xml is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Devinsy-xml. If not, see + */ +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.events.XMLEvent; + +/** + * The Class Foo contains study code. + * + * @author Christian Pierre MOMON (christian.momon@devinsy.fr) + */ +public class Foo +{ + /** + * The main method displays the XML event type reading a XML file + * + * @param args + * the arguments + * @throws Exception + * the exception + */ + public static void main(final String args[]) throws Exception + { + XMLInputFactory factory = XMLInputFactory.newInstance(); + XMLEventReader in = factory.createXMLEventReader(Foo.class.getResourceAsStream("/foo/foo.xml")); + + XMLEvent event; + while (in.hasNext()) + { + event = in.nextEvent(); + + switch (event.getEventType()) + { + case XMLEvent.ATTRIBUTE: + System.out.println("ATTRIBUTE "); + break; + case XMLEvent.CDATA: + System.out.println("CDATA"); + break; + case XMLEvent.CHARACTERS: + System.out.println("CHARACTERS [" + event.asCharacters().getData() + "]"); + break; + case XMLEvent.COMMENT: + System.out.println("COMMENT"); + break; + case XMLEvent.DTD: + System.out.println("DTD"); + break; + case XMLEvent.END_DOCUMENT: + System.out.println("END_DOCUMENT"); + break; + case XMLEvent.END_ELEMENT: + System.out.println("END_ELEMENT " + event.asEndElement().getName()); + break; + case XMLEvent.ENTITY_DECLARATION: + System.out.println("ENTITY_DECLARATION"); + break; + case XMLEvent.ENTITY_REFERENCE: + System.out.println("ENTITY_REFERENCE"); + break; + case XMLEvent.NAMESPACE: + System.out.println("NAMESPACE"); + break; + case XMLEvent.NOTATION_DECLARATION: + System.out.println("NOTATION_DECLARATION"); + break; + case XMLEvent.PROCESSING_INSTRUCTION: + System.out.println("PROCESSING_INSTRUCTION"); + break; + case XMLEvent.SPACE: + System.out.println("SPACE"); + break; + case XMLEvent.START_DOCUMENT: + System.out.println("START_DOCUMENT"); + break; + case XMLEvent.START_ELEMENT: + System.out.println("START_ELEMENT [name=" + event.asStartElement().getName() + "][namespaceURI=" + event.asStartElement().getName().getNamespaceURI() + "][prefix=" + + event.asStartElement().getName().getPrefix() + "][localPart=" + event.asStartElement().getName().getLocalPart() + "]"); + break; + default: + System.out.println("DEFAULT"); + } + } + } +} diff --git a/test/foo/foo.xml b/test/foo/foo.xml new file mode 100644 index 0000000..78f5976 --- /dev/null +++ b/test/foo/foo.xml @@ -0,0 +1,40 @@ + + + + + + Louis / XVI / de France + MALE + + + + 21/1/1793 + + + + complete + + + + Paris + + + + 23/8/1754 + + + + Versailles + + + + aaaaa + + + + Bourbon + + + + +