如何创建以下XML使用Java DOM,我想从头开始创建它.有什么办法吗?我不想读它并克隆它,我只是想通过DOM方法创建它.
Java 例:
Node booking=new Node();
Node bookingID=new Node();
booking.add(bookingID);
Run Code Online (Sandbox Code Playgroud)
XML 例:
<tns:booking>
<tns:bookingID>115</tns:bookingID>
<tns:type>double</tns:type>
<tns:amount>1</tns:amount>
<tns:stayPeriod>
<tns:checkin>
<tns:year>2013</tns:year>
<tns:month>11</tns:month>
<tns:date>14</tns:date>
</tns:checkin>
<tns:checkout>
<tns:year>2013</tns:year>
<tns:month>11</tns:month>
<tns:date>16</tns:date>
</tns:checkout>
</tns:stayPeriod>
</tns:booking>
Run Code Online (Sandbox Code Playgroud) 我正在使用node.js来接收一个帖子请求,请求体在打印后使用以下内容获得此内容console.log():
{
'object 1':
{
deviceType: 'iPad Retina',
guid: 'DF1121F9-FE66-4772-BE74-42936F1357FF',
is_deleted: '0',
last_modified: '1970-12-19T06:01:17.171',
name: 'test1',
projectDescription: '',
sync_status: '1',
userName: 'testUser'
},
'object 0':
{
deviceType: 'iPad Retina',
guid: '18460A72-2190-4375-9F4F-5324B2FCCE0F',
is_deleted: '0',
last_modified: '1970-12-19T06:01:17.171',
name: 'test2',
projectDescription: '',
sync_status: '1',
userName: 'testUser'
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用以下node.js代码获取请求:
var restify = require('restify'),
mongoose = require('mongoose');
var connect = require('connect');
var bodyParser = require('body-parser');
/*server declaration
...
...
*/
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: true }));
server.post('/project', function (req, res, next) {
console.log(req.body);//the …Run Code Online (Sandbox Code Playgroud) 我正在向服务器发送一组对象(如下所示),服务器必须接收对象并将它们添加到 mongodb。我是 node.js 的新手,我通常处理 rcevived 请求正文(req.body)中的键。但在这里,键是对象。我怎样才能迭代它们?
[
{
id: "1",
Name: "John"
},
{
id: "2",
Name: "Mark"
},
{
id: "3",
Name: "Domi"
}
]
Run Code Online (Sandbox Code Playgroud)
服务器代码:
server.get('/user', function (req, res, next) {
//iterate over the objects in req.body
});
Run Code Online (Sandbox Code Playgroud)
当我想发送一个对象时,我可以通过 req.body.id 和 req.body.Name 轻松获取请求内容,那么如何在请求正文中使用多个对象呢?