Search completed in 2.76 seconds.
  
   
    DOMParser - Web APIs
    
 syntax  let domparser = new domparser()  methods  domparser.
parsefromstring()  syntax  let doc = domparser.
parsefromstring(string, mimetype)  return  either document or xmldocument depending on the mimetype argument.
...values are the following:               mimetype     doc.constructor                   text/html     document             text/xml     xmldocument             application/xml     xmldocument             application/xhtml+xml     xmldocument             image/svg+xml     xmldocument              examples  parsing xml  once you have created a parser object, you can parse xml from a string using the 
parsefromstring() method:  let parser = new domparser() let doc = parser.
parsefromstring(stringcontainingxmlsource, "application/xml")   error handling  note that if the parsing process fails, the domparser does not throw an exception, but instead returns an error document:  <parsererror xmlns="http://www.mozilla.org/newlayout/xml/parsererror.xml">   (error description)   <sourcetext>(a snippet of the source xml...
...   if the mime type is text/xml, the result will be an xmldocument  if the mime type is image/svg+xml, the result will be an svgdocument  if the mime type is text/html, the result will be an htmldocument   let parser = new domparser() let doc = parser.
parsefromstring(stringcontainingxmlsource, "application/xml") // returns a document, but not an svgdocument nor an htmldocument  parser = new domparser(); doc = parser.
parsefromstring(stringcontainingsvgsource, "image/svg+xml") // returns a svgdocument, which also is a document.
...And 2 more matches
   
 
   
    Using XML Data Islands in Mozilla - Archive of obsolete content
    
ame>     <price>1.25</price>   </lineitem>   <lineitem>     <name>line item 2</name>     <price>2.48</price>   </lineitem> </purchaseorder> </script>  the xml source text can then be retrieved like this: var ordersource = document.getelementbyid("purchase-order").textcontent;  the xml source text can be parsed into a dom tree using the domparser api: var parser = new domparser(); var doc = parser.
parsefromstring(ordersource, "application/xml"); the html5 data block-based way shown here works in firefox, opera, webkit-based browsers such as chrome and safari, and ie9 while ie's xml data islands work only in ie.
...rder xmlns="http://example.mozilla.org/purchaseorderml">   <lineitem>     <name>line item 1</name>     <price>1.25</price>   </lineitem>   <lineitem>     <name>line item 2</name>     <price>2.48</price>   </lineitem> </purchaseorder> </script> <script> function rundemo() {   var ordersource = document.getelementbyid("purchase-order").textcontent;   var parser = new domparser();   var doc = parser.
parsefromstring(ordersource, "application/xml");   var lineitems = doc.getelementsbytagnamens("http://example.mozilla.org/purchaseorderml", "lineitem");   var firstprice = lineitems[0].getelementsbytagnamens("http://example.mozilla.org/purchaseorderml", "price")[0].textcontent;   document.body.textcontent = "the purchase order contains " + lineitems.length + " line items.
... the price of the first line item is " + firstprice + "."; } </script> </head> <body onload="rundemo()";> demo did not run </body> </html>  the xml source text can be parsed into a dom tree using the domparser api: var parser = new domparser(); var doc = parser.
parsefromstring(ordersource, "application/xml"); the html5 data block-based way shown here works in firefox, opera, webkit-based browsers such as chrome and safari, and ie9 while ie's xml data islands work only in ie.
   
 
   
    nsIFeedProcessor
    
to create an instance, use:  var feedprocessor = components.classes["@mozilla.org/feed-processor;1"]                    .createinstance(components.interfaces.nsifeedprocessor);   method overview           void parseasync(in nsirequestobserver requestobserver, in nsiuri uri);          void parsefromstream(in nsiinputstream stream, in nsiuri uri);          void 
parsefromstring(in astring str, in nsiuri uri);        attributes           attribute    type    description          listener    nsifeedresultlistener    the feed result listener that will respond to feed events.
...  
parsefromstring()  parses a feed from an astring.
...   void 
parsefromstring(    in astring str,    in nsiuri uri  );   parameters    str  the string to parse as a feed.
   
 
   
    Feed content access API
    
.interfaces.nsiioservice);       var uri = ioservice.newuri(feedurl, null, null);        if (data.length) {         var parser = components.classes["@mozilla.org/feed-processor;1"]                                         .createinstance(components.interfaces.nsifeedprocessor);         var listener = new feedtestresultlistener();         try {           parser.listener = listener;           parser.
parsefromstring(data, uri);         }         catch(e) {           alert("error parsing feed.");         }       }     }      httprequest = new xmlhttprequest();      httprequest.open("get", feedurl, true);     try {       httprequest.onload = inforeceived;       httprequest.send(null);     }     catch(e) {       alert(e);     }   }  the nsifeedprocessor interface lets you parse the feed data from several possib...
...le sources; in this case, we're loading a document into a string, then parsing that string using its 
parsefromstring() method.
   
 
   
    nsIDOMParser
    
 parsing a string once you've created a domparser object, you can use its 
parsefromstring method to parse xml or html as described in the web platform documentation.
... examples within the context of a window: var parser = new domparser(); var doc = parser.
parsefromstring(astr, "application/xml");  outside of a window (e.g., a js xpcom component, a js module, or an xpcshell test): var parser = components.classes["@mozilla.org/xmlextras/domparser;1"]              .createinstance(components.interfaces.nsidomparser); var doc = parser.
parsefromstring(astr, "application/xml");  using components.constructor(): const domparser = new components.constructor("@mozilla.org/xmlextras/domparser;1", "nsidomparser"); var parser = new domparser(); parser.init(principal, documenturi, baseuri); var doc = parser.
parsefromstring(astr, "application/xml");                                 ...
   
 
   
    jspage - Archive of obsolete content
    
rn this;}});request.html=new class({extends:request,options:{update:false,append:false,evalscripts:true,filter:false},processhtml:function(c){var b=c.match(/<body[^>]*>([\s\s]*?)<\/body>/i); c=(b)?b[1]:c;var a=new element("div");return $try(function(){var d="<root>"+c+"</root>",g;if(browser.engine.trident){g=new activexobject("microsoft.xmldom"); g.async=false;g.loadxml(d);}else{g=new domparser().
parsefromstring(d,"text/xml");}d=g.getelementsbytagname("root")[0];if(!d){return null;}for(var f=0,e=d.childnodes.length; f<e;f++){var h=element.clone(d.childnodes[f],true,true);if(h){a.grab(h);}}return a;})||a.set("html",c);},success:function(d){var c=this.options,b=this.response; b.html=d.stripscripts(function(e){b.javascript=e;});var a=this.processhtml(b.html);b.tree=a.childnodes;b.elements=a.getelements("*")...
   
 
   
    Microsummary topics - Archive of obsolete content
    
  createinstance(components.interfaces.nsidomparser);  var generatordoc = domparser.
parsefromstring(generatortext, "text/xml");  var microsummaryservice =   components.classes["@mozilla.org/microsummary/service;1"].
   
 
   
    Migrate apps from Internet Explorer to Mozilla - Archive of obsolete content
    
the following code shows you how:  var xmlstring = "<xml id=\"xmldataisland\"><foo>bar</foo></xml>"; var mydocument;  if (window.domparser) {   // this browser appears to support domparser   var parser = new domparser();   mydocument = parser.
parsefromstring(xmlstring, "text/xml"); } else if (window.activexobject){   // internet explorer, create a new xml document using activex   // and use loadxml as a dom parser.
   
 
   
    SAX - Archive of obsolete content
    
below is an example of parsing from a string:  xmlreader.
parsefromstring("<f:a xmlns:f='g' d='1'><bbq/></f:a>", "text/xml");   this call results in the following output (assuming the content handler from the example above is used):  startdocument startelement: namespace='g', localname='a', qname='f:a', attributes={d='1'} startelement: namespace='', localname='bbq', qname='bbq', attributes={} endelement: namespace='', localname='bbq', qname='bbq' endelement: namespace=...
   
 
   
    Writing JavaScript for XHTML - Archive of obsolete content
    
for example:  var string = '<div xmlns="http://www.w3.org/999/xhtml"><h1>hello world!</h1></div>'; var parser = new domparser(); var documentfragment = parser.
parsefromstring(string, "text/xml"); body.appendchild(documentfragment); // assuming 'body' is the body element   but be aware that if your string is not well-formed xml (e.g., you have an & where it should not be), then this method will crash, leaving you with a parser error.
   
 
   
    XForms Custom Controls Examples - Archive of obsolete content
    
	var val = this.stringvalue; 	var newdom = this.domparser.
parsefromstring(val, "text/xml"); 	var impnode = document.importnode(newdom.firstchild, true);  	// get content node, clean it, and update it 	var content = document.getanonymouselementbyattribute(this, "anonid", "content"); 	if (content.firstchild) { 	content.removechild(content.firstchild); 	} 	content.appendchild(impnode);  	return true;       </body>     </method>   </implementation> </binding>              ...
   
 
   
    XML Extras
    
the "workaround" is to use domparser object's 
parsefromstring() method to create a document from string, and pass the temporary document into send().
   
 
   
    DOMParser() - Web APIs
    
this object can be used to parse the text of a document using the 
parsefromstring() method.
   
 
   
    Document.createCDATASection() - Web APIs
    
  example  var docu = new domparser().
parsefromstring('<xml></xml>', 'application/xml')  var cdata = docu.createcdatasection('some <cdata> data & then some');  docu.getelementsbytagname('xml')[0].appendchild(cdata);  alert(new xmlserializer().serializetostring(docu)); // displays: <xml><![cdata[some <cdata> data & then some]]></xml>   notes    this will only work with xml, not html documents (as html documents do not support cdata sections); attempting it on an html document will throw not_supported_err.
   
 
   
    Document.createComment() - Web APIs
    
  example  var docu = new domparser().
parsefromstring('<xml></xml>',  'application/xml'); var comment = docu.createcomment('this is a not-so-secret comment in your document');  docu.getelementsbytagname('xml')[0].appendchild(comment);  alert(new xmlserializer().serializetostring(docu)); // displays: <xml><!--this is a not-so-secret comment in your document--></xml>  specifications           specification    status    comment              domthe definition of 'document.createcomment' in that specification.
   
 
   
  
   
    Document.createProcessingInstruction() - Web APIs
    
      example  var doc = new domparser().
parsefromstring('<foo />', 'application/xml'); var pi = doc.createprocessinginstruction('xml-stylesheet', 'href="mycss.css" type="text/css"');  doc.insertbefore(pi, doc.firstchild);  console.log(new xmlserializer().serializetostring(doc)); // displays: <?xml-stylesheet href="mycss.css" type="text/css"?><foo/>   specifications           specification    status    comment              domthe definition of 'createp...
   
 
   
    Parsing and serializing XML - Developer guides
    
 parsing strings into dom trees  this example converts an xml fragment in a string into a dom tree using a domparser:   var smystring = '<a id="a"><b id="b">hey!</b></a>'; var oparser = new domparser(); var odom = oparser.
parsefromstring(smystring, "application/xml"); // print the name of the root element or error message console.log(odom.documentelement.nodename == "parsererror" ?