Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Load HTML in text strings into HTML parser in Javascript

Reply
Thread Tools

Load HTML in text strings into HTML parser in Javascript

 
 
David Virgil Hobbs
Guest
Posts: n/a
 
      04-09-2006
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.

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      04-09-2006
David Virgil Hobbs wrote:
> 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?

--
Ian Collins.
 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      04-09-2006
David Virgil Hobbs wrote:
> 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.lang.javascript/browse_frm/thread/d9855d899b8a6544/4c4071600634c1ad?q=HTML+to+DOM+Function&rnum=1#4c4 071600634c1ad>


[...]

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


[...]



--
Rob
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Load HTML page into another HTML page using Javascript Duke Javascript 1 04-18-2008 12:16 PM
Checkbox to load text into text area Andy Burghardt Javascript 2 01-31-2008 05:20 PM
Text parser (text into sentences) that works with UTF-8 and multiple languages? mike b. Ruby 3 07-30-2007 12:52 PM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
Load contents of a text file into a text box Jeremy Chapman ASP .Net 1 08-15-2003 10:10 PM



Advertisments