Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6171079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:09:09+00:00 2026-05-23T23:09:09+00:00

I am trying to parse an XML file I made and pull information out

  • 0

I am trying to parse an XML file I made and pull information out of it. I am basing off of this tutorial. The parsing is connecting to the XML file ok and evaluates the first tag but will crash afterwards as seen in the Output. Attached below are the XML File layout, Java parsing code, and the Console Output.

Any idea why it is not reading the next tag of the XML, and if so, what should I change?


XML File:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<filepath>/mnt/sdcard/Audio_Recorder/anonymous22242.3gp</filepath>
<filename>anonymous22242.3gp</filename>
<annotation>
    <file>anonymous22242.3gp</file>
    <timestamp>0:06</timestamp>
    <note>test1</note>
</annotation>
<annotation>
    <file>anonymous22242.3gp</file>
    <timestamp>0:09</timestamp>
    <note>lol</note>
</annotation>
<annotation>
    <file>anonymous22242.3gp</file>
    <timestamp>0:09</timestamp>
    <note>lolol</note>
</annotation>

Java File:

private static String fileDirectory;
private final static ArrayList<String> allFileNames = new ArrayList<String>();
private final static ArrayList<String[]> allAnnotations = new ArrayList<String[]>();
private static String[] currentAnnotation = new String[3];

public static void main(String[] args) {
    // TODO Auto-generated method stub
    try {

        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser playbackParser = factory.newSAXParser();

        DefaultHandler handler = new DefaultHandler() {

            boolean audioFullPath = false;
            boolean audioName = false;
            boolean annotationFile = false;
            boolean annotationTimestamp = false;
            boolean annotationNote = false;

            public void startElement(String uri, String localName,
                    String qName, Attributes attributes)
                    throws SAXException {

                System.out.println("Start Element :" + qName);

                if (qName.equalsIgnoreCase("filepath")) {
                    audioFullPath = true;
                }

                if (qName.equalsIgnoreCase("filename")) {
                    audioName = true;
                }

                if (qName.equalsIgnoreCase("file")) {
                    annotationFile = true;
                }

                if (qName.equalsIgnoreCase("timestamp")) {
                    annotationTimestamp = true;
                }

                if (qName.equalsIgnoreCase("note")) {
                    annotationNote = true;
                }

            }

            public void endElement(String uri, String localName,
                    String qName) throws SAXException {

                System.out.println("End Element :" + qName);

            }

            public void characters(char ch[], int start, int length)
                    throws SAXException {

                if (audioFullPath) {
                    String filePath = new String(ch, start, length);
                    System.out.println("Full Path : " + filePath);
                    fileDirectory = filePath;
                    audioFullPath = false;
                }

                if (audioName) {
                    String fileName = new String(ch, start, length);
                    System.out.println("File Name : " + fileName);
                    allFileNames.add(fileName);
                    audioName = false;
                }

                if (annotationFile) {
                    String fileName = new String(ch, start, length);
                    currentAnnotation[0] = fileName;
                    annotationFile = false;
                }

                if (annotationTimestamp) {
                    String timestamp = new String(ch, start, length);
                    currentAnnotation[1] = timestamp;
                    annotationTimestamp = false;
                }
                if (annotationNote) {
                    String note = new String(ch, start, length);
                    currentAnnotation[2] = note;
                    annotationNote = false;
                    allAnnotations.add(currentAnnotation);
                }

            }

        };

        File file = new File(
                "c:\\Documents and Settings\\anonymous.xml");
        InputStream inputStream = new FileInputStream(file);
        Reader xmlReader = new InputStreamReader(inputStream, "UTF-8");

        InputSource xmlSource = new InputSource(xmlReader);
        xmlSource.setEncoding("UTF-8");

        playbackParser.parse(xmlSource, handler);

        System.out.println(fileDirectory);
        System.out.println(allFileNames);
        System.out.println(allAnnotations);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
}

Output:

Start Element :filepath
Full Path : /mnt/sdcard/Audio_Recorder/anonymous22242.3gp
End Element :filepath
org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$TrailingMiscDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(Unknown Source)
    at main.main(main.java:131)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:09:10+00:00Added an answer on May 23, 2026 at 11:09 pm

    That’s not XML. There must be a single root element containing all of the rest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting this error (see title) while trying to parse an XML file in
I'm trying to parse a XML file using TBXML . However, this parser has
i'm trying to parse this xml file but i can't find a way to
I am trying to parse a xml file that i have (using javascript DOM).
I am trying to parse one XML file that contains some unicode characters.I tried
I'm trying to parse a XML file, but when loading it simpleXML prints the
I'm trying to parse an XML file and one of the fields looks like
I'm trying to parse an xml file from a website. Let's say the website
I am trying XML::SAX parser for parsing XML file. XML file is shown below,
I'm trying to parse a XML File. It worked very well - until today...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.