Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to convert XMLDocument object that I'm getting as a response from an ajax request, to a string. I tried using

new XMLSerializer()).serializeToString(xmlObject)

and I get the following response:-

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:errorList xmlns:ns2="http://www.abc.com/api/delivery/V1"><error code="DOMAIN_VALIDATE" path="delivery.shipper"><message>empty</message></error><error code="DOMAIN_VALIDATE" path="delivery.shipperSite"><message>empty</message></error><error code="DOMAIN_VALIDATE" path="delivery.leg"><message>invalid</message></error></ns2:errorList>

Means the method converted the whole XMLDocument into string, including the very first tag

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

I don't want this part of the response. Is there any method that does that. Note: I don't want to use the workarounds like "substr" etc.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You can do this by serializing just the root node:

new XMLSerializer().serializeToString(xmlObject.documentElement);

Demo: http://jsfiddle.net/timdown/LmWkL/

share|improve this answer
 
Thanks for the resolution @TimDown. It works –  paras2682 Jul 16 '13 at 8:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.