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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:40:32+00:00 2026-05-23T01:40:32+00:00

I have an XML file with a bunch of data contained by custom tags.

  • 0

I have an XML file with a bunch of data contained by custom tags. This is all useful for one project I have, but for another project I don’t need so much info. So I’d like to trim the XML file, and get rid of all instances of certain tags and whatever is between the tags.

<GOBJ>
    <cost>4</cost>
    <duration>n/a</duration>
    <item>Stone Block</item>
    <type>Construction - Material</type>
    <misc>Use these blocks to build things. These blocks don't degrade.</misc>
</GOBJ>

I only want to keep [item]blah[item] and [type]blah[type], the rest should be deleted/removed.

Later on, I will need to check the text of [type] and replace its contents if it matches certain words. For example, if the word metal is anywhere within the [type] tag, then replace the contents of that tag with just the word metal.

I know this is a big request; I appreciate any help.

  • 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-23T01:40:33+00:00Added an answer on May 23, 2026 at 1:40 am

    Another way is to just use simple XML → XML (XSLT 1.0 with XPath 1.0) transformation like below. It’s easy to adapt for your requirements and reuse for other documents.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
        <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
    
        <xsl:template match="root">
            <root>
                <xsl:apply-templates select="GOBJ"/>
            </root>
        </xsl:template>
    
        <xsl:template match="GOBJ">
            <GOBJ>
                <xsl:copy-of select="item"/>
                <type>
                    <xsl:choose>
                        <xsl:when test="contains(type, 'metal')">
                            <xsl:text>metal</xsl:text>
                        </xsl:when>
                        <!-- other xsl:when conditions here -->
                        <xsl:otherwise>
                            <xsl:value-of select="type"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </type>
            </GOBJ>
        </xsl:template>
    </xsl:stylesheet>
    

    I know it’s not regex based solution, but IMHO it’s better to use native XML-oriented toolkit.

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

Sidebar

Related Questions

I have a bunch of hierarchical data stored in an XML file. I am
I have a handful of projects that all use one project for the data
I have this build.xml file http://gist.github.com/315109 . Every task runs smoothly, but test .
I have an XML file that looks something like this: <product> <modelNumber>Data</modelNumber> <salePrice>Data</salePrice> </product>
I have a XML file with the following data format: <net NetName=abc attr1=123 attr2=234
I have created XML file,but I can't view it/output it.I know there is no
i have an xml file sitemap.xml as shown below ..i need to add one
I have student.xml file and am parsing this file using SAX Parser and now
I have a bunch of xml files with a varying amount of data nodes
I am thinking of storing bunch of data in XML files. Each file will

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.