-4

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.

Dale K
  • 25,246
  • 15
  • 42
  • 71
Jatinder Singh
  • 197
  • 3
  • 12
  • Well, have you tried anything yet? What format do you have the XML in at the moment - just as a string, or as an `XDocument` or `XmlDocument`? If you can easily get at it as an `XDocument`, then removing the attribute will be trivial... – Jon Skeet May 16 '17 at 08:43
  • I have an xml document. – Jatinder Singh May 16 '17 at 08:54
  • 1
    Do you mean `XmlDocument`? It's really unclear at the moment. It would be much better if you'd provide a [mcve]. – Jon Skeet May 16 '17 at 08:58

1 Answers1

1

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;
    });
} 
Jatinder Singh
  • 197
  • 3
  • 12