如何创建一个像这样的简单xml文档

| 我想创建一个看起来像这样的xml文档,但我不知道如何:
<bo type=\"Employee\" id=\"0000012f41bce2a865f8616b0010007c0008008b\">
  <username>marv</username>
</bo>
这就是到目前为止,我真的很困惑如何添加
username
元素:
Element bo = testDoc.createElement(\"bo\");
        bo.setAttribute(\"type\", \"Employee\");
        bo.setAttribute(\"id\", emp.getId());
    
已邀请:
Element bo = testDoc.createElement(\"bo\");
bo.setAttribute(\"type\", \"Employee\");
bo.setAttribute(\"id\", emp.getId());
//create a username element
Element username = testDoc.createElement(\"username\");
//add a text value to the username element
username.appendChild(testDoc.createTextNode(\"marv\"));
//add the username element as child of bo element
bo.appendChild(username);
    
创建一个username元素,设置其值,然后使其成为bo元素的子元素。我不知道Java,但是可能有一个AddChild()方法或类似的方法可以使用。     

要回复问题请先登录注册