473,327 Members | 1,896 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,327 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 1269
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 structure: key row desc parent 1 1 A ...
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 when they have virtually nothing in common. The...
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 the expected 4 alerts. In Mozilla/Netscape, I...
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 cells collection, I used the row's childNodes...
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 following example , I want to delete "ns0:Proposal"...
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 version="1.0" encoding="utf-8" ?> <OutlineCodeNames>...
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 TreeNode then does some recursive procedure to add...
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, ie
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.