473,732 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.somefo rm.someinput.va lue is in the loaded text string
containing HTML, the same way I can use javascript to find what
document.somefo rm.someinput.va lue 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.XMLDO M"),
xmlDoc.loadXML( document.form.i nput.value).

Thus, you can for example, find xmlDoc.childNod es(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 2672
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(HTMLstrin g)
{
var d = document.create Element('div');
d.innerHTML = HTMLstring;
var docFrag = document.create DocumentFragmen t();

while (d.firstChild) {
docFrag.appendC hild(d.firstChi ld)
};

return docFrag;
}

<URL:http://groups.google.c om/group/comp.lang.javas cript/browse_frm/thread/d9855d899b8a654 4/4c4071600634c1a d?q=HTML+to+DOM +Function&rnum= 1#4c4071600634c 1ad>
[...]
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
8436
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 this in the HEAD of my document - the page will wait until it downloads. If I place it in the BODY of my document - supposedly the page
4
2717
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 source of the files...
6
3081
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 loaded into the treemenu div. What is the best way to achieve this? I got error where the treemenu didn't close/open on the treenode, as when I clicked on the treenode, it said Object not found. But if I don't use ajaxpage() javascript function, and...
2
2202
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 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...
8
3978
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 seen information on dealing with converting csv to tsv. Specifically I want to take the values and insert them into an html table. I have been trying to figure it out myself, and in essence, this is what I have come up with. Am I on the right...
12
4009
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 //<!]> Is this trick grounded in any real information about HTML vs XHTML? I
12
5620
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
7324
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 I pass the htmllib.HTMLParser UTF-8 code, it chokes. The code is something like this: prs = self.parserclass(formatter.NullFormatter()) prs.init()
4
8415
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 onactivetabindexchanged we have called a method loadtabpanel() which is defined in javascript in same page.the problem is it sometime give the message load tab panel undefined. this error does not come regularly. it comes in usercontrol rendering . i...
0
8944
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9445
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9234
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9180
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.