how can i convert a javascript string to xml string?
convert javascript string to xml string
Collapse
X
-
Tags: None
-
the problem that i am facing is the string that is to be passed to the parseFromString method is a xmlstring. i have an xml file stored in my local file system. but,when i read the file using javascript it is assigned to a javascript string n i m getting a parseerror when i try parse it using parseFromString method.Originally posted by acoder[code=javascript]var XMLobj = (new DOMParser()).pa rseFromString(t heString, "text/xml")[/code]Comment
-
i am storing a string obtained by converting a document fragment using the method serializeToStri ng in the xml file. The problem that i could figure out was the root element of the document fragment is not converted (only the child nodes are converted to string).So the resulting xml doc is not having a root element. How can i fix this??Comment
-
[CODE=javascript]var serializer =Components.cla sses["@mozilla.o rg/xmlextras/xmlserializer;1 "].createInstance (Components.int erfaces.nsIDOMS erializer);
var string = serializer.seri alizeToString(t his.rootnode);
var out = Components.clas ses["@mozilla.o rg/network/file-output-stream;1"].createInstance (Components.int erfaces.nsIFile OutputStream);
out.init(this.f ile, 0x20 | 0x02, 0666, null);
out.write(strin g,string.length );
out.flush();
out.close();[/CODE]Comment
-
Comment