How to add a comment node before the root <svg> element but after the xml prolog?
Or will it be less resource expensive to insert the comment with a regexp on the serialized DOM?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The root element (ie, exclusive of xml prologs and DTDs) is in
documentElement. You can useinsertBeforewith it:To check,
new XMLSerializer().serializeToString(doc)outputs:Note that some browsers (WebKit I believe) will ommit the prolog from the serialized output (it’s optional anyway). However the comment node is still present after the DTD.
As to which is less expensive, I’m not sure. If you don’t need the string in DOM form for anything other than this one thing, it may not be worth going through the DOM parser (especially just to serialize it back to a string anyway).