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

  • SEARCH
  • Home
  • 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 8986099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:28:15+00:00 2026-06-15T21:28:15+00:00

I am new to XML parsing using Java and SAX parser. I have a

  • 0

I am new to XML parsing using Java and SAX parser. I have a really big XML file and because of its size I have been advised to use SAX parser. I have finished parsing part of my tasks and it works as expected. Now, there is one task left with XML job: deleting/updating some nodes upon user’s request.

I am able to find all tags by their names, change their data attributes, etc. If I am able to do these with SAX, deleting also may be possible.

Sample XML describes some functionality under some case’s. User’s inputs are the “case”s names (case1, case2).

<ruleset>
    <rule id="1">
        <condition>
            <case1>somefunctionality</case1>
            <allow>true</allow>
        </condition>
    </rule>
    <rule id="2">
        <condition>
            <case2>somefunctionality</case2>
            <allow>false</allow>
        </condition>
    </rule>
</ruleset>

If user wants to delete one of these cases (for example case1) not just case1 tag, the complete rule tag must be deleted. If case1 is to be deleted, XML will become:

<ruleset>
    <rule id="2">
        <condition>
            <case2>somefunctionality</case2>
            <allow>false</allow>
        </condition>
    </rule>
</ruleset>

My question is, can this be done using SAX? I can’t use DOM or any other parser at this point. Only other option is even worse: string search. How can it be done using SaxParser?

  • 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-06-15T21:28:17+00:00Added an answer on June 15, 2026 at 9:28 pm

    Try as

        XMLReader xr = new XMLFilterImpl(XMLReaderFactory.createXMLReader()) {
            private boolean skip;
    
            @Override
            public void startElement(String uri, String localName, String qName, Attributes atts)
                    throws SAXException {
                if (qName.equals("rule")) {
                    if (atts.getValue("id").equals("1")) {
                        skip = true;
                    } else {
                        super.startElement(uri, localName, qName, atts);
                        skip = false;
                    }
                } else {
                    if (!skip) {
                        super.startElement(uri, localName, qName, atts);
                    }
                }
            }
    
            public void endElement(String uri, String localName, String qName) throws SAXException {
                if (!skip) {
                    super.endElement(uri, localName, qName);
                }
            }
    
            @Override
            public void characters(char[] ch, int start, int length) throws SAXException {
                if (!skip) {
                    super.characters(ch, start, length);
                }
            }
        };
        Source src = new SAXSource(xr, new InputSource("test.xml"));
        Result res = new StreamResult(System.out);
        TransformerFactory.newInstance().newTransformer().transform(src, res);
    

    output

    <?xml version="1.0" encoding="UTF-8"?><ruleset>
        <rule id="2">
            <condition>
                <case2>somefunctionality</case2>
                <allow>false</allow>
            </condition>
        </rule>
    </ruleset>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using SAX Parser to parse the XML file over the network. While
I have a JAVA class in which I have implemented parsing of XML using
I am using the SAX Parser for XML Parsing. The problem is if I
still new to XML parsing with the iphone so i have a few questions.
I am new to xml parsing. I have the following xml <myMainList> <mySubList> <edited>true</edited>
We're parsing an XML document using JAXB and get this error: [org.xml.sax.SAXParseException: Invalid byte
I'm new to xml parsing, I am trying to parse the following xml file
Not new to Java; but relatively new to XML-parsing. I know a tiny bit
I am parsing a string in Java using javax.xml.parsers.DocumentBuilder . However, there is not
I am using the following code by the Android-people-XMLParsing example for parsing XML file

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.