.netjsonnode.jsxmlxml2js

Remove attribute from XML node?


I have some XML which I have to convert to JSON. The XML has nodes like

<Title xml:lang="en">The Steal In The Wheels</Title>

I want to remove this xml:lang="en" from the xml nodes.

Actually, I am working in node.js and I need title value. I am converting XML to JSON using xml2js. It is converting to JSON but it is giving title value with style. So that I am trying to remove this attribute.


Solution

  • I was converting xml to json and when i was trying to get the value of title then it was coming with style.

    So that i asked this question. Now i got the solution so that i want to share with you if anybody from you stucked like me then it will help you.

    Here is the code:

    
    var xml2js = require('xml2js');
    
    function GetRequestBody(data){
            
            var parser = new xml2js.Parser({ignoreAttrs : true, mergeAttrs : false});
            parser.parseString(data.toString(), function (err, result) {
            var post_data = querystring.stringify({
                              'name' : result.Documents.Content[0].Title 
                          });
                
             return post_data;
            });
        }