An example analysis NodeJS module XML2JS parses the pit encountered during the XML process

The instance of this paper tells the NodeJS module XML2JS to resolve the pit encountered during the XML process. Share to everyone for reference, specifically:

In one project, the NodeJS module XML2JS parses XML, XML data is as follows:

      
The XML2JS.Parstring method in XML2JS is analyzed, it is thought to be a JSON, but it always resolves failed. The results of the resolution Log subsequently followed by:

{xml: {msgid: [‘6197906553041859764’]}}

  The  package in this XML is a string, and the result is resolved is an array. 
After the XML2JS official website was found, and the following parameters were found:

ExplicitArray (default: true): Always Put Child Nodes in An Array If True; OtherWise An Array IS CREATED ONLY INLY THERE Is More Than One.

The original XML2JS will change the value of the child node by default to an array, this pit is really big! ! ! In order to check this problem, spent half a day.

After knowing the reason, the method of solving is also very simple. The parameters joined EXPLICITARRAY when calling XML2JS.ParsString:

XML2JS.PARSSTRING (BUF, {ExplicitArray: false}, FuncTION (ERR, JSON) {};

After modification, the following results are as follows:
   
{XML : {Msgid: ‘6197906553041859764’}

Now become a string.

PS: Here you will provide you with a number of online tools for XML operations for your reference:
   Online XML / JSON mutual conversion tool:
http://tools.jb51.net/code/xmljson

Online format XML / online compression XML:

http: //tools.jb51. NET / CODE / XMLFORMAT

Online Compressed / Format Tools:

http://tools.jb51.net/code/xml_format_compress
XML

Code online formatting beauty tool:
http://tools.jb51.net/code/xmlcodeformat

Wispi Everyone NodeJS program is helpful.

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment