472,353 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

help with extracting nodes and their children as text

I'm loading an xml data file and then trying to take a particular node
and add it, as html, to an element on my page using inner HTML. The
xml is like what is below, with the ... representing eliminated
detail:

<?xml version="1.0" encoding="iso-8859-1"?>
<table>
<descriptions>
<fielddesc id="1">
...
</fielddesc>
...
</descriptions>
<recordset>
<record id="1">
<field id="1">1</field>
<field id="2">Hydrogen</field>
<field id="3">H</field>
<field id="4">[not applicable]</field>
<field id="5">[not applicable]</field>
<field id="6">[not applicable]</field>
<field id="7">1s<sup>1</sup></field>
</record>
...
</recordset>
</table>

The problem comes with id 7 above. I want to get everything that is
contained in that field and use it in my page so that the <sup> html
tag is used. Here are some things I've tried:

recordset = table.getElementsByTagName('recordset')[0].getElementsByTagName('record');
valueIwant = recordset[1].getElementsByTagName('field')[7].firstChild.data;
(This only gets everything up to the <sip> tag)

recordset = table.getElementsByTagName('recordset')[0].getElementsByTagName('record');
valueIwant = recordset[1].getElementsByTagName('field')[7].text;
(This only works on IE and it doesn't format the contents in the <sup>
tag)

Anybody have some suggestions on how to do what I want?

Thanks,
Rob
Jul 20 '05 #1
4 1230
Am I missing something? You write: valueIwant = recordset[1] ...
('field')[7] ...

Shouldn't that be recordset[0] and ...('field')[6] ?

recordset =
table.getElementsByTagName('recordset')[0].getElementsByTagName('record');
valueIwant = recordset[1].getElementsByTagName('field')[7].firstChild.data; (This only gets everything up to the <sip> tag)

recordset = table.getElementsByTagName('recordset')[0].getElementsByTagName('record'); valueIwant = recordset[1].getElementsByTagName('field')[7].text;
(This only works on IE and it doesn't format the contents in the <sup>
tag)


Jul 20 '05 #2


Robert Fentress wrote:
I'm loading an xml data file and then trying to take a particular node
and add it, as html, to an element on my page using inner HTML. The
xml is like what is below, with the ... representing eliminated
detail:

<?xml version="1.0" encoding="iso-8859-1"?>
<table>
<descriptions>
<fielddesc id="1">
...
</fielddesc>
...
</descriptions>
<recordset>
<record id="1">
<field id="1">1</field>
<field id="2">Hydrogen</field>
<field id="3">H</field>
<field id="4">[not applicable]</field>
<field id="5">[not applicable]</field>
<field id="6">[not applicable]</field>
<field id="7">1s<sup>1</sup></field>
</record>
...
</recordset>
</table>

The problem comes with id 7 above. I want to get everything that is
contained in that field and use it in my page so that the <sup> html
tag is used. Here are some things I've tried:

recordset = table.getElementsByTagName('recordset')[0].getElementsByTagName('record');
valueIwant = recordset[1].getElementsByTagName('field')[7].firstChild.data;
(This only gets everything up to the <sip> tag)

recordset = table.getElementsByTagName('recordset')[0].getElementsByTagName('record');
valueIwant = recordset[1].getElementsByTagName('field')[7].text;
(This only works on IE and it doesn't format the contents in the <sup>
tag)

Anybody have some suggestions on how to do what I want?


Well, an XML element with tagname sup is not an HTML element, if you
target XHTML you would need
<sup xmlns="http://www.w3.org/1999/xhtml">...</sup>
that way a browser like Mozilla would allow you to import that node from
the XML document into an XHTML document:
http://home.arcor.de/martin.honnen/j...20040206.xhtml

IE however doesn't understand XHTML and doesn't support importNode so
there you are better off trying to insert some snippet of markup using
insertAdjacentHTML or innerHTML. XSLT transformations might be a way
with IE to create that snippet of HTML markup from your XML.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3
Antenna <q1****************@hotmail.com> wrote in message news:<c0**********@news.worldonline.be>...
Am I missing something? You write: valueIwant = recordset[1] ...
('field')[7] ...

Shouldn't that be recordset[0] and ...('field')[6] ?


Yes. I realized that after I sent it. Doesn't affect the issue though.

Rob
Jul 20 '05 #4
Martin Honnen <ma*******@yahoo.de> wrote in message news:<40********@olaf.komtel.net>...
Well, an XML element with tagname sup is not an HTML element, if you
target XHTML you would need
<sup xmlns="http://www.w3.org/1999/xhtml">...</sup>
that way a browser like Mozilla would allow you to import that node from
the XML document into an XHTML document:
http://home.arcor.de/martin.honnen/j...20040206.xhtml

IE however doesn't understand XHTML and doesn't support importNode so
there you are better off trying to insert some snippet of markup using
insertAdjacentHTML or innerHTML. XSLT transformations might be a way
with IE to create that snippet of HTML markup from your XML.


Thanks for your help Martin. I'll try to do some research on XSLT so
I can get it to work on IE too.

Rob
Jul 20 '05 #5

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

Similar topics

2
by: csx | last post by:
Hi all, I'm trying to count the number of leafnodes for a particular node. What im trying to do is make a function, that taking the tree...
8
by: Xamle Eng | last post by:
One of the things I find most unnatural about most XML APIs is that they try to abstract both elements and text into some kind of "node" object...
13
by: kaeli | last post by:
Can anyone explain this to me? It's driving me insane. Save this and run it in IE or Opera and then in Mozilla or Netscape 6+. In IE/Opera, I get...
2
by: RobG | last post by:
Why does Firefox insert #text nodes as children of TR elements? As a work-around for older Safari versions not properly supporting a table row's...
6
by: Nikhil Patel | last post by:
Hi all, Following is a portion of an XML document. I need to remove all nodes that belong to ns0 without deleting their child nodes. So in the...
2
by: AGB | last post by:
Hi all, I have the following simple XML file. I would like to load all the values in the Name nodes into a drop-down list box: <?xml...
2
by: Kristopher Wragg | last post by:
I'm having some serious problems with the TreeView control. I've got a control that inherits TreeView and has some methods that firstly create a...
4
by: reflex | last post by:
I have to get every node within range or selection? Is it possible? Sry for my engrish :] Ref
8
by: nicolas.edel | last post by:
Hi, suppose i get the simple xml sample: <foo> 1 <bar>2</bar> 3 </foo> Now suppose i want to extract all the text of only the 'foo' node,...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.