Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-15-2005, 07:47 PM   PM User | #1
idn
New to the CF scene

 
Join Date: Dec 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
idn is an unknown quantity at this point
Getting innerText bewteen node in XML document

Hi,

I am having problems getting the inner value of a node in an xmldocument.

Below is a sample of the document:

Code:
<help>
	<topic id="1" admin="false">
		<question>How do I change the relationship between this portal and other portals in the related portals section?</question>
		<answer>The portals can be arranged in a hierarchical structure to allow users to better navigate between the different portals, if you want a portal to appear underneath another portal, or want another portal to be listed under this portal, please contact the <a href="mailto:jbolt@foo.com">admin</a> stating which portal you want to move and where you want to move it to.</answer>
	</topic>
	<topic id="2" admin="false">

		<question>How do I retire a portal?</question>
		<answer>Please contact the <a href="mailto:jbolt@foo.com">admin</a> stating which portal needs to be retired. By retiring the portal, the relevant modifier will no longer be visible in the document id tool; however the portal and all its documentation will still be accessible by viewing the <a href="http://dmportls-wxp/dmportls/?modifier=RETIRED">RETIRED</a> portal.</answer>
	</topic>
</help>
When I use the code

Code:
xmlDoc.getElementsByTagName("answer")[1].firstChild.nodeValue
I only get the string

Code:
Please contact the
It doesnt retrieve the <a> tag or anything after it, is there something similar to teh innerHTML funciton you can use on HTML elements to get the complete contents of a tag?

Thanks!
idn is offline   Reply With Quote
Old 12-15-2005, 08:31 PM   PM User | #2
fishluvr
Regular Coder

 
fishluvr's Avatar
 
Join Date: Nov 2005
Posts: 110
Thanks: 1
Thanked 12 Times in 12 Posts
fishluvr is on a distinguished road
Try changing your < > to &lt; and &gt; inside your "answer" tags in the xml file. They are creating additional child nodes.
fishluvr is offline   Reply With Quote
Old 12-15-2005, 08:40 PM   PM User | #3
Basscyst
Smokes a Lot


 
Join Date: Jul 2003
Location: CA, USA
Posts: 1,594
Thanks: 5
Thanked 20 Times in 20 Posts
Basscyst is on a distinguished road
Or if for some reason you can't do that, you can try something liek this:

Code:
function writeData(req)
			{
				doc=req.documentElement;
				var ans=doc.getElementsByTagName('answer')
				var len=ans.length;
				var obj=document.getElementById('data_spot')
				for(var i=0;i<len;i++)
				{
					var kids=ans[i].childNodes;
					for(var j=0;j<kids.length;j++)
					{
						if(!kids[j].tagName)
						{
							obj.innerHTML+=kids[j].nodeValue;
						}
						else if(kids[j].tagName&&kids[j].tagName.toLowerCase()=='a')
						{
							var a=document.createElement('a');
							a.setAttribute('href',kids[j].getAttribute('href'));
							a.innerHTML=kids[j].text;
							obj.appendChild(a);
						}
					}
					obj.appendChild(document.createElement('hr'));
				}
			}
Basscyst
__________________
Helping to build a bigger box. - Adam Matthews
Basscyst is offline   Reply With Quote
Old 12-15-2005, 08:45 PM   PM User | #4
idn
New to the CF scene

 
Join Date: Dec 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
idn is an unknown quantity at this point
Great, it works! Thanks alot, it's a shame I have to do it as it makes the XML a little less readable, never mind though.

If you have any ideas for this thread, it would be awesome

Thanks!
idn is offline   Reply With Quote
Old 12-15-2005, 08:47 PM   PM User | #5
idn
New to the CF scene

 
Join Date: Dec 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
idn is an unknown quantity at this point
Quote:
Originally Posted by Basscyst
Or if for some reason you can't do that, you can try something liek this:

Code:
function writeData(req)
			{
				doc=req.documentElement;
				var ans=doc.getElementsByTagName('answer')
				var len=ans.length;
				var obj=document.getElementById('data_spot')
				for(var i=0;i<len;i++)
				{
					var kids=ans[i].childNodes;
					for(var j=0;j<kids.length;j++)
					{
						if(!kids[j].tagName)
						{
							obj.innerHTML+=kids[j].nodeValue;
						}
						else if(kids[j].tagName&&kids[j].tagName.toLowerCase()=='a')
						{
							var a=document.createElement('a');
							a.setAttribute('href',kids[j].getAttribute('href'));
							a.innerHTML=kids[j].text;
							obj.appendChild(a);
						}
					}
					obj.appendChild(document.createElement('hr'));
				}
			}

Basscyst


Thanks, I'll check out your code and get back to you!
idn is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:45 AM.


Advertisement
Log in to turn off these ads.