Refactored foo code.
This commit is contained in:
parent
418e9243ca
commit
5a5bd040ce
3 changed files with 143 additions and 73 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
103
test/foo/Foo.java
Normal file
103
test/foo/Foo.java
Normal file
|
@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
40
test/foo/foo.xml
Normal file
40
test/foo/foo.xml
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<corpus xmlns="urn:schema:PUCK/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="PUCK-1.0" generator="PUCK" date="2013-05-14T00:21:40.421+02:00" filename="t.puc">
|
||||
<attributes/>
|
||||
<individuals>
|
||||
<individual id="1">
|
||||
<name>Louis / XVI / de France</name>
|
||||
<gender>MALE</gender>
|
||||
<attributes size="7">
|
||||
<attribute>
|
||||
<label>DEAT Date</label>
|
||||
<value>21/1/1793</value>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<label>COMPL</label>
|
||||
<value>complete</value>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<label>DEAT Place</label>
|
||||
<value>Paris</value>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<label>BIRT Date</label>
|
||||
<value>23/8/1754</value>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<label>BIRT Place</label>
|
||||
<value>Versailles</value>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<label>SHEET</label>
|
||||
<value>aaaaa</value>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<label>DYNASTY</label>
|
||||
<value>Bourbon</value>
|
||||
</attribute>
|
||||
</attributes>
|
||||
</individual>
|
||||
</individuals>
|
||||
</corpus>
|
Loading…
Reference in a new issue