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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:55:16+00:00 2026-05-30T22:55:16+00:00

I am trying to create the following example. <body> <resources> <string-array name=mytest> <item number=1>

  • 0

I am trying to create the following example.

<body>
  <resources>
    <string-array name="mytest">
      <item number="1">
        <name>Testname</name>
      </item>
      <item number="2">
        <name>blaat..</name>
      </item>
    </string-array>
  </resources>
</body>

I try this by doing the following:

FileInputStream fis = openFileInput("test1.xml");

Document doc = Jsoup.parse(fis, "UTF-8", "");
Node node = doc.getElementsByTag("item").get(getPosition());

fis.close();
fis = openFileInput("test2.xml");
Document doc2 = Jsoup.parse(fis, "UTF-8", "");
fis.close();

Elements test = doc2.getElementsByTag("resources");
if(test.size() < 0){
fis = openFileInput("test2.xml");
doc2 = Jsoup.parse(fis, "UTF-8", "");
fis.close();
doc2.appendElement("resources").parent();
FileOutputStream os = openFileOutput("test2.xml", Context.MODE_PRIVATE);
os.write(doc2.toString().getBytes());
os.close();

fis = openFileInput("test2.xml");
doc2 = Jsoup.parse(fis, "UTF-8", "");
fis.close();
doc2.appendChild(doc2.appendElement("string-array").attr("name", "mytest")).parent();
os = openFileOutput("test2.xml", Context.MODE_PRIVATE);
os.write(doc2.toString().getBytes());
os.close();

System.out.println("Created file\n");
}

doc2.appendChild(node);
FileOutputStream os = openFileOutput("test2.xml", Context.MODE_PRIVATE);

os.write(doc2.toString().getBytes()); 
os.close();

And what i get now is:

<!-- test1.xml (input) -->
<resources>
  <string-array name="firsttest">
    <item number="1">
      <name>Testname</name>
    </item>
    <item number="2">
      <name>blaat..</name>
    </item>
    <item number="3">
      <name>Next item</name>
    </item>
  </string-array>
</resources>

<!-- test2.xml (output)-->
<body>
  <resources></resources>
  <string-array name="mytest"></string-array>
  <item number="1">
    <name>Testname</name>
  </item>
  <item number="2">
    <name>blaat..</name>
  </item>
</body>

Can anybody tell me what i’m doing wrong and maybe give me some examples on how it should be done?

Thanks in advance

EDIT: To give a bit more detail: I want to copy some items from test1.xml to test2.xml. So basically the user selects a listitem that points to a number in text1.xml (item number) and that item should then be copied into the (ITEM HERE

  • 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-30T22:55:17+00:00Added an answer on May 30, 2026 at 10:55 pm

    Jsoup is generally used for parsing html, not xml, although they have same structure. By default, Jsoup parses anything, then wraps it inside <html><body>…</body></html>.

    An example for your goal:

    import org.jsoup.nodes.*;
    
    Document doc = Jsoup.parse("");
    // clear <html><body></body></html>
    doc.html("");
    
    Element e = doc.appendElement("body").appendElement("resources");
    
    e = e.appendElement("string-array");
    e.attr("name", "mytest");
    
    for (int i = 0; i < 10; i++) {
        Element sub = e.appendElement("item");
        sub.attr("number", Integer.toString(i));
        sub.appendElement("name").text("blahh");
    }
    

    References:

    • parse(String)
    • html(String)
    • appendElement(String)
    • attr(String, String)
    • text(String)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following example http://jsfiddle.net/xBRPg/ I'm trying to create a yellow background for one
I'm trying to create my first test application with NHibernate following example in NHibernate
I'm trying to create a menu in Qt following this example http://doc.qt.nokia.com/latest/mainwindows-menus.html but I
I am trying to create a table with the following: CREATE TABLE GTW_WORKFLOW_MON (
I'm trying the following: CREATE TABLE Table1 ( RecordNo autonumber, --error here! PersonId varchar(50),
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
Trying to create a list to return some JSON data to a view. Following
I am trying to create a checkbox dynamically using following HTML/JavaScript. Any ideas why
I'm trying to create an algorithm in C# which produces the following output strings:
I am trying to create an expression tree that represents the following: myObject.childObjectCollection.Any(i =>

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.