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

The Archive Base Latest Questions

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

Is there an easy way (perhaps using the DOM api, or other) where I

  • 0

Is there an easy way (perhaps using the DOM api, or other) where I could remove the actual data from an XML file, leaving behind just a kind of template of its schema, so that we can see what potential information it can hold.

I will give an example, to make this clear.

Consider the users inputs the following xml file:

<photos page="2" pages="89" perpage="10" total="881">
    <photo id="2636" owner="47058503995@N01" 
        secret="a123456" server="2" title="test_04"
        ispublic="1" isfriend="0" isfamily="0" />
    <photo id="2635" owner="47058503995@N01"
        secret="b123456" server="2" title="test_03"
        ispublic="0" isfriend="1" isfamily="1" />
    <photo id="2633" owner="47058503995@N01"
        secret="c123456" server="2" title="test_01"
        ispublic="1" isfriend="0" isfamily="0" />
    <photo id="2610" owner="12037949754@N01"
        secret="d123456" server="2" title="00_tall"
        ispublic="1" isfriend="0" isfamily="0" />
</photos>

Then I want to transform this into:

<photos page=“..." pages=“..." perpage=“..." total=“...">
    <photo id=“.." owner=“.." 
        secret=“..." server=“..." title=“..."
        ispublic=“..." isfriend=“..." isfamily=“...” />
</photos>

I’m sure this could be written manually, but would be the be best, most efficient and reliable way of doing this. (preferably in Java).

Thnx!

  • 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-23T20:39:40+00:00Added an answer on May 23, 2026 at 8:39 pm

    There are plenty of possibilities:

    • DOM API (included in JDK)
    • SAX API (included in JDK)
    • JDOM (easy to use, but external)
    • XSLT (transforming XML with prepared XSL stylesheet, JDK supports XSLT 1.0)

    I think that XSLT is most reliable and universal way to transform XML into another XML. Here is some quick example:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:strip-space elements="*"/>
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    
        <xsl:template match="node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()[position()=1]"/>
            </xsl:copy>     
        </xsl:template>
    
        <xsl:template match="@*">
            <xsl:attribute name="{name()}">...</xsl:attribute>
        </xsl:template>
    </xsl:stylesheet>
    

    Result:

    <photos page="..." pages="..." perpage="..." total="...">
       <photo id="..." owner="..." secret="..." server="..." title="..." ispublic="..."
              isfriend="..."
              isfamily="..."/>
    </photos>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an easy way to produce MSDN-style documentation from the Visual Studio XML
Is there an easy way to read an entire Access file (.mdb) into a
Is there an easy way of using the RegularExpressionValidator control while ignoring white space?
Is there an easy way to get the relative complement of two sets? Perhaps
Aside from using -nostdlib and linking crt1.o -lc -lgcc yourself, is there any easy
Is there an easy way to iterate over an associative array of this structure
Is there an easy way in C# to create Ordinals for a number? For
Is there an easy way to avoid dealing with text encoding problems?
Is there an easy way to tell if a ruby script is already running
Is there an easy way to set the zoom level for a windows form

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.