开发者

How to create a simple xml doc like this one

I am wantin开发者_如何学JAVAg to create an xml doc that looks like this but I don't know how to:

<bo type="Employee" id="0000012f41bce2a865f8616b0010007c0008008b">
  <username>marv</username>
</bo>

this is what I have so far, I'm really just confused as how to add the username element:

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);


Create a username element, set it's value, then make it a child of the bo element. I don't know Java but there is probably an AddChild() method or similar you can use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜