<? xml version ="1.0" encoding ="UTF-8" standalone ="no" ? >
< doc >
< id > 3 </ id >
< fam > </ fam >
< name > </ name >
< otc > </ otc >
< dateb > 10-03-2005 </ dateb >
< datep > 10-03-2005 </ datep >
< datev > 10-03-2005 </ datev >
< datebegin > 09-06-2009 </ datebegin >
< dateend > 10-03-2005 </ dateend >
< vdolid > 1 </ vdolid >
< specid > 1 </ specid >
< klavid > 1 </ klavid >
< stav > 2.0 </ stav >
< progid > 1 </ progid >
</ doc >
* This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="UTF-8" standalone ="no" ? >
< doc >
< id > 3 </ id >
< fam > </ fam >
< name > </ name >
< otc > </ otc >
< dateb > 10-03-2005 </ dateb >
< datep > 10-03-2005 </ datep >
< datev > 10-03-2005 </ datev >
< datebegin > 09-06-2009 </ datebegin >
< dateend > 10-03-2005 </ dateend >
< vdolid > 1 </ vdolid >
< specid > 1 </ specid >
< klavid > 1 </ klavid >
< stav > 2.0 </ stav >
< progid > 1 </ progid >
</ doc >
* This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="UTF-8" standalone ="no" ? >
< doc >
< id > 3 </ id >
< fam > </ fam >
< name > </ name >
< otc > </ otc >
< dateb > 10-03-2005 </ dateb >
< datep > 10-03-2005 </ datep >
< datev > 10-03-2005 </ datev >
< datebegin > 09-06-2009 </ datebegin >
< dateend > 10-03-2005 </ dateend >
< vdolid > 1 </ vdolid >
< specid > 1 </ specid >
< klavid > 1 </ klavid >
< stav > 2.0 </ stav >
< progid > 1 </ progid >
</ doc >
* This source code was highlighted with Source Code Highlighter .
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.*;
* This source code was highlighted with Source Code Highlighter .
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.*;
* This source code was highlighted with Source Code Highlighter .
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.*;
* This source code was highlighted with Source Code Highlighter .
public class SAXPars extends DefaultHandler{
...
}
* This source code was highlighted with Source Code Highlighter .
public class SAXPars extends DefaultHandler{
...
}
* This source code was highlighted with Source Code Highlighter .
public class SAXPars extends DefaultHandler{
...
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void startDocument() throws SAXException {
System. out .println( "Start parse XML..." );
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void startDocument() throws SAXException {
System. out .println( "Start parse XML..." );
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void startDocument() throws SAXException {
System. out .println( "Start parse XML..." );
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void startElement( String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
thisElement = qName;
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void startElement( String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
thisElement = qName;
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void startElement( String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
thisElement = qName;
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void characters( char [] ch, int start, int length) throws SAXException {
if (thisElement.equals( "id" )) {
doc.setId( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "fam" )) {
doc.setFam( new String (ch, start, length));
}
if (thisElement.equals( "name" )) {
doc.setName( new String (ch, start, length));
}
if (thisElement.equals( "otc" )) {
doc.setOtc( new String (ch, start, length));
}
if (thisElement.equals( "dateb" )) {
doc.setDateb( new String (ch, start, length));
}
if (thisElement.equals( "datep" )) {
doc.setDatep( new String (ch, start, length));
}
if (thisElement.equals( "datev" )) {
doc.setDatev( new String (ch, start, length));
}
if (thisElement.equals( "datebegin" )) {
doc.setDatebegin( new String (ch, start, length));
}
if (thisElement.equals( "dateend" )) {
doc.setDateend( new String (ch, start, length));
}
if (thisElement.equals( "vdolid" )) {
doc.setVdolid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "specid" )) {
doc.setSpecid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "klavid" )) {
doc.setKlavid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "stav" )) {
doc.setStav( new Float( new String (ch, start, length)));
}
if (thisElement.equals( "progid" )) {
doc.setProgid( new Integer( new String (ch, start, length)));
}
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void characters( char [] ch, int start, int length) throws SAXException {
if (thisElement.equals( "id" )) {
doc.setId( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "fam" )) {
doc.setFam( new String (ch, start, length));
}
if (thisElement.equals( "name" )) {
doc.setName( new String (ch, start, length));
}
if (thisElement.equals( "otc" )) {
doc.setOtc( new String (ch, start, length));
}
if (thisElement.equals( "dateb" )) {
doc.setDateb( new String (ch, start, length));
}
if (thisElement.equals( "datep" )) {
doc.setDatep( new String (ch, start, length));
}
if (thisElement.equals( "datev" )) {
doc.setDatev( new String (ch, start, length));
}
if (thisElement.equals( "datebegin" )) {
doc.setDatebegin( new String (ch, start, length));
}
if (thisElement.equals( "dateend" )) {
doc.setDateend( new String (ch, start, length));
}
if (thisElement.equals( "vdolid" )) {
doc.setVdolid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "specid" )) {
doc.setSpecid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "klavid" )) {
doc.setKlavid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "stav" )) {
doc.setStav( new Float( new String (ch, start, length)));
}
if (thisElement.equals( "progid" )) {
doc.setProgid( new Integer( new String (ch, start, length)));
}
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void characters( char [] ch, int start, int length) throws SAXException {
if (thisElement.equals( "id" )) {
doc.setId( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "fam" )) {
doc.setFam( new String (ch, start, length));
}
if (thisElement.equals( "name" )) {
doc.setName( new String (ch, start, length));
}
if (thisElement.equals( "otc" )) {
doc.setOtc( new String (ch, start, length));
}
if (thisElement.equals( "dateb" )) {
doc.setDateb( new String (ch, start, length));
}
if (thisElement.equals( "datep" )) {
doc.setDatep( new String (ch, start, length));
}
if (thisElement.equals( "datev" )) {
doc.setDatev( new String (ch, start, length));
}
if (thisElement.equals( "datebegin" )) {
doc.setDatebegin( new String (ch, start, length));
}
if (thisElement.equals( "dateend" )) {
doc.setDateend( new String (ch, start, length));
}
if (thisElement.equals( "vdolid" )) {
doc.setVdolid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "specid" )) {
doc.setSpecid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "klavid" )) {
doc.setKlavid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "stav" )) {
doc.setStav( new Float( new String (ch, start, length)));
}
if (thisElement.equals( "progid" )) {
doc.setProgid( new Integer( new String (ch, start, length)));
}
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void endElement( String namespaceURI, String localName, String qName) throws SAXException {
thisElement = "" ;
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void endElement( String namespaceURI, String localName, String qName) throws SAXException {
thisElement = "" ;
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void endElement( String namespaceURI, String localName, String qName) throws SAXException {
thisElement = "" ;
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void endDocument() {
System. out .println( "Stop parse XML..." );
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void endDocument() {
System. out .println( "Stop parse XML..." );
}
* This source code was highlighted with Source Code Highlighter .
@Override
public void endDocument() {
System. out .println( "Stop parse XML..." );
}
* This source code was highlighted with Source Code Highlighter .
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.*;
public class SAXPars extends DefaultHandler{
Doctors doc = new Doctors();
String thisElement = "" ;
public Doctors getResult(){
return doc;
}
@Override
public void startDocument() throws SAXException {
System. out .println( "Start parse XML..." );
}
@Override
public void startElement( String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
thisElement = qName;
}
@Override
public void endElement( String namespaceURI, String localName, String qName) throws SAXException {
thisElement = "" ;
}
@Override
public void characters( char [] ch, int start, int length) throws SAXException {
if (thisElement.equals( "id" )) {
doc.setId( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "fam" )) {
doc.setFam( new String (ch, start, length));
}
if (thisElement.equals( "name" )) {
doc.setName( new String (ch, start, length));
}
if (thisElement.equals( "otc" )) {
doc.setOtc( new String (ch, start, length));
}
if (thisElement.equals( "dateb" )) {
doc.setDateb( new String (ch, start, length));
}
if (thisElement.equals( "datep" )) {
doc.setDatep( new String (ch, start, length));
}
if (thisElement.equals( "datev" )) {
doc.setDatev( new String (ch, start, length));
}
if (thisElement.equals( "datebegin" )) {
doc.setDatebegin( new String (ch, start, length));
}
if (thisElement.equals( "dateend" )) {
doc.setDateend( new String (ch, start, length));
}
if (thisElement.equals( "vdolid" )) {
doc.setVdolid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "specid" )) {
doc.setSpecid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "klavid" )) {
doc.setKlavid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "stav" )) {
doc.setStav( new Float( new String (ch, start, length)));
}
if (thisElement.equals( "progid" )) {
doc.setProgid( new Integer( new String (ch, start, length)));
}
}
@Override
public void endDocument() {
System. out .println( "Stop parse XML..." );
}
}
* This source code was highlighted with Source Code Highlighter .
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.*;
public class SAXPars extends DefaultHandler{
Doctors doc = new Doctors();
String thisElement = "" ;
public Doctors getResult(){
return doc;
}
@Override
public void startDocument() throws SAXException {
System. out .println( "Start parse XML..." );
}
@Override
public void startElement( String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
thisElement = qName;
}
@Override
public void endElement( String namespaceURI, String localName, String qName) throws SAXException {
thisElement = "" ;
}
@Override
public void characters( char [] ch, int start, int length) throws SAXException {
if (thisElement.equals( "id" )) {
doc.setId( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "fam" )) {
doc.setFam( new String (ch, start, length));
}
if (thisElement.equals( "name" )) {
doc.setName( new String (ch, start, length));
}
if (thisElement.equals( "otc" )) {
doc.setOtc( new String (ch, start, length));
}
if (thisElement.equals( "dateb" )) {
doc.setDateb( new String (ch, start, length));
}
if (thisElement.equals( "datep" )) {
doc.setDatep( new String (ch, start, length));
}
if (thisElement.equals( "datev" )) {
doc.setDatev( new String (ch, start, length));
}
if (thisElement.equals( "datebegin" )) {
doc.setDatebegin( new String (ch, start, length));
}
if (thisElement.equals( "dateend" )) {
doc.setDateend( new String (ch, start, length));
}
if (thisElement.equals( "vdolid" )) {
doc.setVdolid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "specid" )) {
doc.setSpecid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "klavid" )) {
doc.setKlavid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "stav" )) {
doc.setStav( new Float( new String (ch, start, length)));
}
if (thisElement.equals( "progid" )) {
doc.setProgid( new Integer( new String (ch, start, length)));
}
}
@Override
public void endDocument() {
System. out .println( "Stop parse XML..." );
}
}
* This source code was highlighted with Source Code Highlighter .
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.*;
public class SAXPars extends DefaultHandler{
Doctors doc = new Doctors();
String thisElement = "" ;
public Doctors getResult(){
return doc;
}
@Override
public void startDocument() throws SAXException {
System. out .println( "Start parse XML..." );
}
@Override
public void startElement( String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
thisElement = qName;
}
@Override
public void endElement( String namespaceURI, String localName, String qName) throws SAXException {
thisElement = "" ;
}
@Override
public void characters( char [] ch, int start, int length) throws SAXException {
if (thisElement.equals( "id" )) {
doc.setId( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "fam" )) {
doc.setFam( new String (ch, start, length));
}
if (thisElement.equals( "name" )) {
doc.setName( new String (ch, start, length));
}
if (thisElement.equals( "otc" )) {
doc.setOtc( new String (ch, start, length));
}
if (thisElement.equals( "dateb" )) {
doc.setDateb( new String (ch, start, length));
}
if (thisElement.equals( "datep" )) {
doc.setDatep( new String (ch, start, length));
}
if (thisElement.equals( "datev" )) {
doc.setDatev( new String (ch, start, length));
}
if (thisElement.equals( "datebegin" )) {
doc.setDatebegin( new String (ch, start, length));
}
if (thisElement.equals( "dateend" )) {
doc.setDateend( new String (ch, start, length));
}
if (thisElement.equals( "vdolid" )) {
doc.setVdolid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "specid" )) {
doc.setSpecid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "klavid" )) {
doc.setKlavid( new Integer( new String (ch, start, length)));
}
if (thisElement.equals( "stav" )) {
doc.setStav( new Float( new String (ch, start, length)));
}
if (thisElement.equals( "progid" )) {
doc.setProgid( new Integer( new String (ch, start, length)));
}
}
@Override
public void endDocument() {
System. out .println( "Stop parse XML..." );
}
}
* This source code was highlighted with Source Code Highlighter .
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
SAXPars saxp = new SAXPars();
parser.parse( new File ( "..." ), saxp);
* This source code was highlighted with Source Code Highlighter .
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
SAXPars saxp = new SAXPars();
parser.parse( new File ( "..." ), saxp);
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/62757/
All Articles