Load HTML in text strings into HTML parser in Javascript

  • Thread starter David Virgil Hobbs
  • Start date
D

David Virgil Hobbs

Loading text strings containing HTML code into an HTML parser in a
Javascript/Jscript

I would like to know, how one would go about loading a text string
containing HTML code, so as to be able to use javascript or Jscript to
work with the HTML code in the text string, in the same way that one
works with XML code in a text string using the XML parser.

If I was able to load the text string containing the HTML code
succesfully, I would be able to for example, find what
document.someform.someinput.value is in the loaded text string
containing HTML, the same way I can use javascript to find what
document.someform.someinput.value is in the HTML that is on the same
page as the javascript.

Microsoft's xml parser, allows you to load a text string containing xml
code, such as text in an html form input, and then use javascript to
work with this text string containing xml code, as if you were working
with an xml.

The syntax for this is, var xmlDoc=new
ActiveXObject("MICROSOFT.XMLDOM"),
xmlDoc.loadXML(document.form.input.value).

Thus, you can for example, find xmlDoc.childNodes(0).nodeName etc etc
inside the text string that is loaded into the Parser.

It has been surprisingly tough going trying to figure out how to do
this if possible, using search engines. Seems being able to do what I
seek to do, is fundamental to the teaching and learning of
HTML/DHTML/CSS/Javascript.
 
I

Ian Collins

David said:
Loading text strings containing HTML code into an HTML parser in a
Javascript/Jscript

I would like to know, how one would go about loading a text string
containing HTML code, so as to be able to use javascript or Jscript to
work with the HTML code in the text string, in the same way that one
works with XML code in a text string using the XML parser.
Have you tried creating a DOM element and setting it's innerHTML to your
string?
 
R

RobG

David said:
Loading text strings containing HTML code into an HTML parser in a
Javascript/Jscript

I would like to know, how one would go about loading a text string
containing HTML code, so as to be able to use javascript or Jscript to
work with the HTML code in the text string, in the same way that one
works with XML code in a text string using the XML parser.

A JavaScript function posted about a week ago (it lacks feature
detection and is only lightly tested):

function toDOM(HTMLstring)
{
var d = document.createElement('div');
d.innerHTML = HTMLstring;
var docFrag = document.createDocumentFragment();

while (d.firstChild) {
docFrag.appendChild(d.firstChild)
};

return docFrag;
}

<URL:http://groups.google.com/group/comp...=HTML+to+DOM+Function&rnum=1#4c4071600634c1ad>


[...]
Microsoft's xml parser, allows you to load a text string containing xml
code, such as text in an html form input, and then use javascript to
work with this text string containing xml code, as if you were working
with an xml.

The W3C DOM 3 Load and Save includes interfaces for parsing and
serialising XML, however they aren't widely implemented yet.

<URL:http://www.w3.org/TR/DOM-Level-3-LS/load-save.html>


[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top