473,800 Members | 2,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

grabbing HTML from within XML

Hi, old web developer, new to Ajax and XML here.
I'm developing an application that grabs an XML file from a (PHP) web
service. In fact, it's going to be an online game. When the user
clicks a map location it accesses a service that provides information
about that location in a form something like this:

<maplocation locID="###" picturesrc="ima ge.jpg">
<name>...</name>
<breadcrumbs>.. .</breadcrumbs>
<description>.. .</description>
</maplocation>

The problem for me is the <descriptionele ment. If the writers give
me a plain text description, fine, I can insert it into my web page's
DOM with the innerHTML property of an existing <spantag or whatever.

However, I want my descriptions to be able to contain HTML (thus the
<descriptionnod e may have an unknown number of child nodes) which
then gets inserted into the DOM. I can't figure out how to do it.
I've tried wrapping the description in a <divtag, like this:

<maplocation>
<description>
<div>
this is the most <i>interestin g</ilocation in the game...
</div>
</description>
</maplocation>

I tried grabbing it with the firstChild property of my <description>
element, and using appendChild() to stick it in a <divin the DOM,
but it doesn't work. I've checked the nodeName property and made sure
what I was grabbing was the "div", but nothing appears on my page.
How can I achieve this?

May 29 '07 #1
5 1926
On May 29, 9:25 am, joe_doufu <joeclar...@gma il.comwrote:
Hi, old web developer, new to Ajax and XML here.
Silly me, I tell you I'm a long-time web developer and then pull a
newbie trick like forgetting to tell you what browser I'm testing in!
(It's IE 6)

May 29 '07 #2
On May 29, 11:25 am, joe_doufu <joeclar...@gma il.comwrote:
Hi, old web developer, new to Ajax and XML here.
I'm developing an application that grabs an XML file from a (PHP) web
service. In fact, it's going to be an online game. When the user
clicks a map location it accesses a service that provides information
about that location in a form something like this:

<maplocation locID="###" picturesrc="ima ge.jpg">
<name>...</name>
<breadcrumbs>.. .</breadcrumbs>
<description>.. .</description>
</maplocation>

The problem for me is the <descriptionele ment. If the writers give
me a plain text description, fine, I can insert it into my web page's
DOM with the innerHTML property of an existing <spantag or whatever.

However, I want my descriptions to be able to contain HTML (thus the
<descriptionnod e may have an unknown number of child nodes) which
then gets inserted into the DOM. I can't figure out how to do it.
I've tried wrapping the description in a <divtag, like this:

<maplocation>
<description>
<div>
this is the most <i>interestin g</ilocation in the game...
</div>
</description>
</maplocation>

I tried grabbing it with the firstChild property of my <description>
element, and using appendChild() to stick it in a <divin the DOM,
but it doesn't work. I've checked the nodeName property and made sure
what I was grabbing was the "div", but nothing appears on my page.
How can I achieve this?
Markup the HTML using a CDATA section:

<maplocation>
<description>
<![CDATA[
<div>
this is the most <i>interestin g</ilocation in the game...
</div>
]]>
</description>
</maplocation>

<URL: http://www.w3.org/TR/xml/#sec-cdata-sect >
You might find it faster to use JSON, which is XML-ish but can be
turned directly into a javascript object so you can access its
properties and values:

<URL: http://www.json.org/ >
--
Rob

May 29 '07 #3
On May 29, 10:58 am, RobG <r...@iinet.net .auwrote:
Markup the HTML using a CDATA section:

<maplocation>
<description>
<![CDATA[
<div>
this is the most <i>interestin g</ilocation in the game...
</div>
]]>
</description>
</maplocation>
Thanks for the pointer! It worked fine in IE 6, but there was a
problem with Firefox. FF decided that the CDATA object wasn't the
"firstChild " node of the <description> , in fact the firstChild was a
text node full of whitespace. It works in both browsers when I drop
the whitespace as in:

<description> <![CDATA[
blah blah blah
]]></description>

May 29 '07 #4
On May 29, 12:29 pm, joe_doufu <joeclar...@gma il.comwrote:
On May 29, 10:58 am, RobG <r...@iinet.net .auwrote:
Markup the HTML using a CDATA section:
<maplocation>
<description>
<![CDATA[
<div>
this is the most <i>interestin g</ilocation in the game...
</div>
]]>
</description>
</maplocation>

Thanks for the pointer! It worked fine in IE 6, but there was a
problem with Firefox. FF decided that the CDATA object wasn't the
"firstChild " node of the <description> , in fact the firstChild was a
text node full of whitespace. It works in both browsers when I drop
the whitespace as in:

<description> <![CDATA[
blah blah blah
]]></description>
Why don't you just escape the html and put it to the description tag
as plain text - &lt;div&gt;s ome text&lt;/div&gt; In this way it will
all be just one child, no need for CDATA, and every browser will work
the same. When you get it, if the browser doesn't automatically
unescape the <>&"' signs, you can do it manually, with replace etc.
Then you can put it to the innerHTML property.

May 29 '07 #5
How about using a "filter":

myVars = myXML.childNode s;

function myFunc() {
for (i=0; i<=myVars.lengt h-1; i++) {
if (myVars[i].nodeType = 3) { // element node = type 3
// your function here
}
}
}

or similar. I forget the original code but it was actually explained
in an article in developer.mozil la.org. Note that the Firefox case is
not a bug/quirk. Indeed, it's IE's quirk that the trailing whitespaces
after the <descriptionele ment don't take any account.

=============== =============== =============== =============== ===

On May 29, 5:29 pm, joe_doufu <joeclar...@gma il.comwrote:
On May 29, 10:58 am, RobG <r...@iinet.net .auwrote:
Markup the HTML using a CDATA section:
<maplocation>
<description>
<![CDATA[
<div>
this is the most <i>interestin g</ilocation in the game...
</div>
]]>
</description>
</maplocation>

Thanks for the pointer! It worked fine in IE 6, but there was a
problem with Firefox. FF decided that the CDATA object wasn't the
"firstChild " node of the <description> , in fact the firstChild was a
text node full of whitespace. It works in both browsers when I drop
the whitespace as in:

<description> <![CDATA[
blah blah blah
]]></description>
May 29 '07 #6

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

Similar topics

5
2599
by: Joe | last post by:
I need to connect to 10 web sites to grab content from them. I would like to connect to each site simultaneously so that I can obtain the data as fast as possible. I am familar doing this with perl by using parallel sockets or the module LWP-Parallel. So what would be the best method to do this in php? Sockets, forks? Also, if possible, could someone provide me with a good reference site that will help me accomplish this?
4
1312
by: InvisibleMan | last post by:
Hi, Thanks for any help in advance... I'm wondering if anyone knows how or has the resource for graabing a users email address without them knowing? Before I hear all the 'Its not ethical' blurb - I know and my use is legitimate... I am build an e-commerce store and as well as grabbing the users IP at point of sale, i think it would be invaluable to grab a
4
1394
by: darrel | last post by:
I have a contact form that a person submits to the server. In ASP, you'd make a page, post the form to another page, which would grab the values and do somethign with them. in ASP.NET, it appears that you grab the values directly from the form objects on the postback. Here's our problem:
0
831
by: darrel | last post by:
I'm using a string builder to build an HTML table using data from a dataset. Normally, I'd grab the data, fill a data set with it, then access the fields as such: ds.Tables(0).Rows(0)("fieldName") Easy enough. Now, this time, I'm trying to do the same, but I'm implementing pageData as well. My initial thought is that I can't do this from the codebhind side and
0
1599
by: .Net Sports | last post by:
I've been looking everywhere, but i can't locate any functions, or articles on the net or my resources, on how to open a file using vb.net, and then grabbing certain parts of the file, and putting it into a useable variable. I know there are functions like Split, Len, Trim, etc., but I have found nothing as far as the sequence for the syntax. I am interested in grabbing the first line, or first 50 characters for example, and then being...
7
1758
by: MaryA | last post by:
Let me preface this with the fact that I am a newbie to HTML, XML and Javascript. Having said that, let me explain my dilemma: I am having a difficult time getting innerHTML to consistently return the entire HTML string when a <p> is part of the text. It somehow throws everything off. I am trying to store exam questions in an Oracle Database as XML. The XML I started with looked like this: <aicpcu id="XMLTEXT"><stem id="STEM">This...
4
1325
by: Efrat Regev | last post by:
Hello, Suppose I want to run from within a Python GUI app some long-output shell call. For example, from within Python I might want to call g++ foo.cpp I already know there are many ways to do this, e.g., commands.getstatusoutput('g++ foo.cpp') to name one.
4
1962
by: code937 | last post by:
Hey guys, Im making a stupidly simple CMS and i guess the best way to save data for each page is within an sql database. The only thing is, from past experience, when you echo data from a database it usually just echos the text (i.e. <font color="#FFFFFF">Hello</font> instead of echoing Hello in white. Anywho, if you think im going the wrong way about it please prod me in the right directions. Cheers
1
2113
roswara
by: roswara | last post by:
Dear all, Currently, I am working on a project to make a web-based application using ASP 2.0 and C#. This application will ask user to input for an excel file which has graphs in it. Then the application will grab the graph as image file, and this image will be displayed as thumbnail in the page. Is it possible to accomplish this feature? If it is possible, would you please tell me how? And if it is not possible, why?
0
9695
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
10514
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
10287
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...
0
10042
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...
1
7588
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6826
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
5479
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
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3770
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.