我目前正在尝试使用xml2js通过meteor解析XML并将其插入Mongodb。我在server / fixtures.js中使用以下代码执行此操作:
Iati.insert({
test: xml2js.parseString(Assets.getText('iati.xml'))
})
Xml2js确实似乎转换了一些东西,但输出似乎没有意义,即具有以下属性的对象:
test: Object
ENTITIES: Object
attribList: Array[0]
attribName: ""
attribValue: ""
bufferCheckPosition: 65536
c: ""
cdata: ""
closed: false
closedRoot: false
column: 0
comment: ""
doctype: ""
entity: ""
error: null
line: 0
looseCase: "toUpperCase"
noscript: true
opt: Object
position: 0
procInstBody: ""
procInstName: ""
q: ""
sawRoot: false
script: ""
sgmlDecl: ""
startTagPosition: 9347
state: 0
strict: true
tag: null
tagName: ""
tags: Array[0]
textNode: ""
trackPosition: true
__proto__: Object
__proto__: Object
我应该如何更改代码以获取实际的XML作为输出?提前谢谢
答案 0 :(得分:1)
根据the documentation,您需要传递回调xml2js.parseString
才能获得实际值:
xml2js.parseString(Assets.getText('iati.xml'), function(err, res) {
Iati.insert({
test: res,
});
});