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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:02:33+00:00 2026-06-14T18:02:33+00:00

I ran into a problem while developing onto Blackberry. I am using KXML2 api

  • 0

I ran into a problem while developing onto Blackberry. I am using KXML2 api for XML parsing (well actually, I got someone else’s code to continue and fix, so I have to use this). The problem is the lack of cloning in java me, and im having some difficulities when trying to deep copy a node. (I dont want to go into details, but the point is, that i need to substitue data into specific points of a html and there is an xml describer for that) So..! 🙂

XMLElement childNode = node.getElement(ci);

This is the element I need to copy. XMLElement is a simple wrapper class, never mind that, it contains and Element attribute and some useful methods.

Now what I want is kind of like something like this :

XMLElement newChildNode = childNode.clone();

Since there is no cloning, no clonable interface in Java ME, I cannot do that, and this only creates a reference to the original element, which i need to preserve, while modifying the new element:

XMLElement newChildNode = childNode;

Can anyone come up with a usable idea about, how to create a deep copy of my childNode element? Thank you very much in advance!

  • 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-14T18:02:35+00:00Added an answer on June 14, 2026 at 6:02 pm

    I managed to solve the problem with this simple utility function. It simply iterates through the attributes, copies them and recursively calls the function if needed.

    public static Element createClone(Element toClone) {
    
    
                String namespace = (toClone.getNamespace() == null) ? "" : toClone.getNamespace();
                String name = (toClone.getName() == null) ? "" : toClone.getName();
    
                Element result = toClone.createElement(namespace, name);
    
                int childCount = toClone.getChildCount();
                int attributeCount = toClone.getAttributeCount();
    
                for (int i = 0; i < attributeCount; i++) {
    
                    result.setAttribute(toClone.getAttributeNamespace(i), toClone.getAttributeName(i), toClone.getAttributeValue(i));
                }                       
    
                for (int j = 0; j < childCount; j ++) {
    
                        Object childObject = toClone.getChild(j);
                        int type = toClone.getType(j);
    
                        if (type == Node.ELEMENT) {
    
                                Element child = (Element) childObject;
                                result.addChild(Node.ELEMENT, createClone(child));
    
                        } else if (type == Node.TEXT) {
    
                            String childText = new String((String) childObject);
    
                            if (!childText.equals("")) {
                                result.addChild(Node.TEXT, childObject);
                            }
    
                        } 
                    }
    
    
                return result;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while working on a school project i ran into a problem using javascript to
I ran into a problem while trying to parse an XML string returned from
I've ran into a problem recently while developing with Spring Security. It has an
I just ran into a problem while developing a login system. I build a
While building a Search for my app i ran into a problem whilst using
I ran into this problem while developing in Objective-C for iOS, but this should
I'm developing in MVC2 using VB.NET and MySQL and ran into a problem trying
While trying out an experimental UINavigationController-based iPhone application, I ran into a problem when
I ran in to an interesting problem while using the 'tap' method on objects
While creating an online shop application using play-1.2.4 ,I ran into some problems with

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.