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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:32:18+00:00 2026-05-26T14:32:18+00:00

In the XML example below, using a java parser how to keep the content

  • 0

In the XML example below, using a java parser how to keep the content under the tag AND followed by center and remove everything else?
The tag might have other instances when is followed by other tags than center, and those has to be discarded.

<xml>
    <A> 
        <B>
        .
        .
        .

            <parameter>
                <parameterid>center</parameterid>
                <name>Center</name>
                <keyframe>
                    <when>1</when>
                    <value>
                        <horiz>100</horiz>
                        <vert>100</vert>
                    </value>
                </keyframe>
                <keyframe>
                <when>2</when>
                    <value>
                        <horiz>150</horiz>
                        <vert>150</vert>
                    </value>
                </keyframe>
            </parameter>
            <parameter>
                ...
            </parameter>
            <parameter>
                ...
            </parameter>
        .
        .
        .
        </B>
    </A>
</xml>

So the output will look like:

<parameter>
    <parameterid>center</parameterid>
    <name>Center</name>
    <keyframe>
        <when>1</when>
        <value>
            <horiz>100</horiz>
            <vert>100</vert>
        </value>
    </keyframe>
    <keyframe>
    <when>2</when>
        <value>
            <horiz>150</horiz>
            <vert>150</vert>
        </value>
    </keyframe>
</parameter>

Please advise. Thanks!

  • 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-26T14:32:19+00:00Added an answer on May 26, 2026 at 2:32 pm

    You can use Java Regexp to remove unneeded content, and then parse only needed part f.e.

    String sourceXML = readFileToString("source.xml")
    final Pattern pattern = Pattern.compile(".*(<parameter>.+</parameter>).*",Pattern.DOTALL);
    Matcher matcher = pattern.matcher(sourceXML);
    if (matcher.find()) {
       String xmlToParse = matcher.group(0);
       someDomOrSaxParser.parseFromString(xmlToParse)
    }else 
       System.out.println("NO MATCH");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My current LINQ query and example XML are below. What I'd like to do
Example XML using element nodes: <?xml version=1.0 encoding=utf-8?> <users> <user> <name>David Smith</name> <phone>0441 234443</phone>
Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
I have below xml and I am using VBSript to generate it. <?xml version=1.0?>
I have an XML file like below , using xpath and xnavigator how can
Is using an if coupled with an immediate return like in the example below
I have an xml document that I am creating using the loop below and
I have an XML file (example below) and it is sitting somewhere on the
Look at the test code I have written below. Using pure java I set
I have the following XML example <?xml version=1.0?> <test> <items> <item>item 1</item> <item>item 2</item>

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.