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 4330752
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:00:23+00:00 2026-05-21T10:00:23+00:00

Given the following scenario, where the xml, Geography.xml looks like – <Geography xmlns:ns=some valid

  • 0

Given the following scenario, where the xml, Geography.xml looks like –

<Geography xmlns:ns="some valid namespace">
    <Country>
        <Region>
            <State>
                <City>
                    <Name></Name>
                    <Population></Population>
                </City>
            </State>
            </Region>
        </Country>
    </Geography>

and the following sample java code –

InputStream is = new FileInputStream("C:\\Geography.xml");
SAXBuilder saxBuilder = new SAXBuilder();
Document doc = saxBuilder.build(is);

XPath xpath = XPath.newInstance("/*/Country/Region/State/City");
Element el = (Element) xpath.selectSingleNode(doc);
boolean b = doc.removeContent(el);

The removeContent() method doesn’t remove the Element City from the content list of the doc. The value of b is false
I don’t understand why is it not removing the Element, I even tried to delete the Name & Population elements from the xml just to see if that was the issue but apparently its not.
Another way I tried, I don’t know why I know its not essentially different, still just for the sake, was to use Parent –

Parent p = el.getParent();
boolean s = p.removeContent(new Element("City"));

What might the problem? and a possible solution? and if anyone can share the real behaviour of the method removeContent(), I suspect it has to do with the parent-child relationship.

  • 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-21T10:00:24+00:00Added an answer on May 21, 2026 at 10:00 am

    Sure, removeContent(Content child) removes child if child belongs to the parents immediate children, which it does not in your case. Use el.detach()instead.

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

Sidebar

Related Questions

I have the following scenarios: Scenario: Create a game with valid information Given I
Given the following scenario, I would like to know if functionOneLock releases itself before
I'd like to know what happens given the following scenario using the .net client.
Given following array: var arr = [undefined, undefined, 2, 5, undefined, undefined]; I'd like
I'm using SpecFlow, and I'd like to write a scenario such as the following:
Given the following scenario, which one of the following is preferred. m_state is a
The following scenario pretty much sums up my problem: Scenario: problems with subprocesses Given
Given the following scenario, please suggest me a way to implement memcache in my
I got stuck with the following scenario like I have two timers. If user
Given the following scenario Start off with this structure: Trunk\blah\ Tag\ I branch Trunk

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.