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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:17:06+00:00 2026-05-26T00:17:06+00:00

I want to create a Document object with jdom. I have written a function

  • 0

I want to create a Document object with jdom. I have written a function but after I debug I can see that it is not created. and since I am new to XML I don’t understand why I can not create. Can you please help me for that?

public Document createSNMPMessage (){

    Element root = new Element("message");
    Document document = new Document(root);

    Element header = new Element("header");

    Element messageType = new Element("messageType").setText("snmp");
    Element sendFrom = new Element("sendFrom").setText("192.168.0.16");
    Element hostName = new Element("hostName").setText("oghmasysMehmet");
    Element sendTo = new Element("sendTo").setText("192.168.0.12");
    Element receiverName = new Element("receiverName").setText("Mehmet");
    Element date = new Element("date").setText("03/10/2011");

    header.addContent(messageType);
    header.addContent(sendFrom);
    header.addContent(hostName);
    header.addContent(sendTo);
    header.addContent(receiverName);
    header.addContent(date);

    Element body = new Element("body");

    Element snmpType = new Element("snmpType").setText("getbulk");
    Element ip = new Element("ip").setText("127.0.0.1");
    Element port = new Element("port").setText("161");
    Element oids = new Element("oids");
    Element oid = new Element("oid").setText("1.3.6.1.2.1.1.3.0");
    oids.addContent(oid);
    Element community = new Element("community").setText("community");
    Element nR = new Element("nR").setText("0");
    Element mR = new Element("mR").setText("5");

    body.addContent(snmpType);
    body.addContent(ip);
    body.addContent(port);
    body.addContent(oids);
    body.addContent(community);
    body.addContent(nR);
    body.addContent(mR);

    return document;

}

When I create it, I convert it to string by using that function ;

    public String xmlToString(Document doc) {
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    return outputter.outputString(doc);
}

and When I try to convert to string to see what is inside of the Document, i get;

<?xml version="1.0" encoding="UTF-8"?>
<message />
  • 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-26T00:17:06+00:00Added an answer on May 26, 2026 at 12:17 am

    From what I can see, you are creating a Document object, and adding nodes to the header and body nodes, but these nodes are not being added to your Document object instance document.

    I believe you would want to add these nodes to the root element, which is already added to your document.

    So, you could add it to your document’s root as shown below:

    public Document createSNMPMessage (){
    
        Element root = new Element("message");
        Document document = new Document(root);
    
        Element header = new Element("header");
    
        ...
        ...
    
        Element body = new Element("body");
    
        ...
        ...
    
        root.addContent(header);  // NOTE THESE NEW LINES
        root.addContent(body);  // NOTE THESE NEW LINES
    
        return document;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document and want to create it as a twocolumn-document. That works
I want to create an object that is globally accessible after the DOM has
i want to create a new '.b' div appendTo document.body, and it can dragable
I want to create a word 2007 document without using object model. So I
I want to create an XML document from object list. How to handle Null
I need to create a XML Document object using the NodeList. Can someone pls
I want to create a 'File' object that returns 'Line' objects when the ReadLine()
I want to create a number of div s that I can move and
I have the following code in Javascript: jQuery(document).ready(function(){ var actions = new Object(); var
We want to create a common document library on a certain site level and

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.