[英]Finding XML elements by type and ID in node.js
我对node.js有点陌生,对将它与XML结合使用确实很陌生。 我无法弄清楚如何根据元素的ID和类型在XML文档中找到特定的元素。
基本上,我想做的是使用Express处理请求,然后在请求中使用查询字符串中的值,在XML文档中搜索元素,然后将该元素的内容作为响应发送回去。
这是我的一些代码:
var express = require('express'),
xmlDoc = require('document.xml'),
app = express();
app.get('/', function(req, res){
var id = req.query.id;
/* Here's where I want to get the element from xmlDoc based on id and element type*/
res.send(/* Send the contents of the element */)
});
app.listen(3000);
提前致谢!
您需要使用一些XML解析器,例如libxmljs , xmldoc或node-xml2js ,这是XML到JS对象的转换器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.