473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Load HTML in text strings into HTML parser in Javascript

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.

Apr 9 '06 #1
2 11181
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.
Apr 9 '06 #2
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
Apr 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ed Brandmark | last post by:
I have a tag of the form <SCRIPT LANGUAGE="JavaScript1.1" SRC="foo.js"..... and was wondering if this delays the loading of my page until that file foo.js downloads. It seems that if I place...
4
by: Don Wash | last post by:
Hi All! I'm getting the following Error: No DLLs has been compiled yet and nothing in the \bin directory. So it is not the versioning problem or anything like that. And here are the...
6
by: acord | last post by:
Hi, In a html page, I don't know how to load in a php page from javascript. I've already defined a <div id="treemenu"> in the html page. The executed content from the php script is supposed...
2
by: David Virgil Hobbs | last post by:
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...
8
by: Brian | last post by:
I was wondering if anyone here on the group could point me in a direction that would expllaing how to use python to convert a tsv file to html. I have been searching for a resource but have only...
12
by: Peter Michaux | last post by:
Hi, I am experimenting with some of the Ruby on Rails JavaScript generators and see something I haven't before. Maybe it is worthwhile? In the page below the script is enclosed in //<!]> ...
12
by: Geoff Cox | last post by:
Hello I'm having a problem loading a frameset file using an include in a php file. Nothing is displayed and when I look at the source code I see that <html> <head> <title></title>
5
by: Johannes Bauer | last post by:
Hello group, I'm trying to use a htmllib.HTMLParser derivate class to parse a website which I fetched via httplib.HTTPConnection().request().getresponse().read(). Now the problem is: As soon as...
4
hemantbasva
by: hemantbasva | last post by:
We have designed an aspx page having five ajax tab in it. the data of first four are designed on page whereas for the fifth tab it renders a user control named MYDOMAIN. in the tab container's even...
11
Dormilich
by: Dormilich | last post by:
Lately I have seen so much awful HTML, that I like to show what a HTML document should look like, regarding the requirements from the W3C. the absolute minimum is defined as: or expressed in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.