本文介绍了NodeJS XMLDOM-设置序列化后丢失的DOM值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用nodejs xmldom模块来调用SOAP服务。在致电服务之前,我必须
设置电话号码

I am using nodejs xmldom module to call a SOAP service. Before calling the service, I have toset the phone number

代码如下

    var fs = require('fs');
    var xmldoc = fs.readFileSync('req.xml', 'utf8');

    var DOMParser = require('xmldom').DOMParser;
    var doc = new DOMParser().parseFromString(
        xmldoc
        ,'text/xml');

    //change phone number from xxxxxx to 83834324838 (dummy)
    doc.getElementsByTagName('msisdn').item(0).firstChild.nodeValue = '83834324838';

    var phone = doc.getElementsByTagName('msisdn').item(0).firstChild.nodeValue;

    // logs 83834324838
    console.log(phone);

    // serialize DOM back to xml
    var XMLSerializer = require('xmldom').XMLSerializer;
    var serializedXML = new XMLSerializer().serializeToString(doc);

    var inspect = require('util').inspect;

    //!!serialized XML doesnt have the 83834324838
    console.log(inspect(serializedXML, {
        colors: true,
        depth: Infinity
    }));


    //call to SOAP service

变量serializedXML没有我设置的电话号码(83834324838)。我检查了DOM文档,发现设置msisdn / phone_number的方式是正确的(console.log(phone)证明了这一点)。但是一旦将DOM序列化回XML字符串,我就失去了新的数字。

The variable serializedXML does not have the phone number that I set (83834324838). I checked DOM documentation and I see that the way I am setting the msisdn/phone_number is right (console.log(phone) proves that). But once serialize the DOM back into XML string, I just lose the new number.

到此为止。有人可以刺死吗?

At wits end here. Can anyone please take a stab at this?

推荐答案

这是XMLDOM模块中的错误:

It's a bug in the XMLDOM module:

我想还有其他的Node.js模块可以完成这项工作。 怎么样? (免责声明:通过快速搜索发现。我从未使用过。)

I imagine there are other Node.js modules that do the job. How about libxmljs? (Disclaimer: found through a quick search. I've never used it.)

这篇关于NodeJS XMLDOM-设置序列化后丢失的DOM值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 22:00