Answer the question
In order to leave comments, you need to log in
How to parse multiple XML files using SAX in Java?
I can't start parsing several XML files from one folder
. Here is the program code:
Here I upload files
public static void main(String[] args) throws IOException
{
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(false);
SAXParser parser;
//InputStream xmlData = null;
try
{
BufferedReader xmlData = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\XMLExamples")));
parser = factory.newSAXParser();
parser.parse(xmlData, new MyParser());
}
}
Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
System.out.println("Тег: "+qName);
if(qName.equals("HEADER"))
System.out.println("IDFILE: "+attributes.getValue("IDFILE"));
System.out.println("S_ID: "+attributes.getValue("S_ID"));
// System.out.println(attributes.getLength());
super.startElement(uri, localName, qName, attributes);
}
@Override
public void characters(char[] c, int start, int length)
throws SAXException {
super.characters(c, start, length);
for(int i=start;i< start+length;++i)
System.err.print(c[i]);
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
System.out.println("Tag done: "+qName);
super.endElement(uri,localName, qName);
}
@Override
public void startDocument() throws SAXException {
System.out.println("Start parsing doc!");
super.startDocument();
}
@Override
public void endDocument() throws SAXException {
super.endDocument();
System.out.println("Parsing finished!");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question