0

I have found a lot of working example for this problem but no one is working in my case. I will be having following response from server and need to get value between "Message" tags.

<?xml version="1.0" encoding="utf-8"?>
<BaseResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns="http://tempuri.org/">
<Message>uYnxLHnBJPtBp9K8GNg```F4v5YPP4HIgOxN@@@DjwPIUpA=p</Message>
<Status>true</Status>
<Code>200</Code>
</BaseResponse>

will be grateful if anyone can please help me to sort it out.

P.S:- For reference I tried it using http://jsfiddle.net/RPbSE/ but no success

2 Answers 2

1

Based on your example all you have to do is get the inner html of the message tag using a dom parser

var text, parser, xmlDoc;

text = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<BaseResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://tempuri.org/\">" +
"<Message>uYnxLHnBJPtBp9K8GNg```F4v5YPP4HIgOxN@@@DjwPIUpA=p</Message>" +
"<Status>true</Status>" + 
"<Code>200</Code>" +
"</BaseResponse>";

parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"text/xml");


alert(xmlDoc.getElementsByTagName("Message")[0].innerHTML );

Here's a working fiddle for you: https://jsfiddle.net/zeq5g47t/

Sign up to request clarification or add additional context in comments.

Comments

0

You could try the DOMParser api

var parser = new DOMParser();
var doc = parser.parseFromString(`<?xml version="1.0" encoding="utf-8"?>
<BaseResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns="http://tempuri.org/">
<Message>uYnxLHnBJPtBp9K8GNgF4v5YPP4HIgOxN@@@DjwPIUpA=p</Message>
<Status>true</Status>
<Code>200</Code>
</BaseResponse>`,"application/xml");
doc.querySelector("Message").innerHTML

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.