Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
155
rated 0 times [  161] [ 6]  / answers: 1 / hits: 51999  / 11 Years ago, tue, july 16, 2013, 12:00:00

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.example.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.


More From » xml

 Answers
27

You can do this by serializing just the root node:



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


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


[#76974] Monday, July 15, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kourtney

Total Points: 368
Total Questions: 103
Total Answers: 85

Location: Bonaire
Member since Sat, May 1, 2021
3 Years ago
;