473,396 Members | 1,765 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,396 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 2186
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.