?
Solved

Adding &nbsp

Posted on 2006-05-12
6
Medium Priority
?
719 Views
Last Modified: 2008-01-09
So, here is the code that is stepping through XML data and creating  img src's with a href's. That's working fine now.
However , I can't figure out how to put "&nbsp" in between each image.

// get the href data from the XML DOM
var data=entry[m].getElementsByTagName("entrydata");
var text=data[1].getElementsByTagName("text");
var tdata=text[0].firstChild.nodeValue;

//create a node and set href  
var ref = document.createElement("a");
ref.setAttribute("href",tdata);
img.insertBefore(ref);

//get the image data from the XML DOM
var data=entry[m].getElementsByTagName("entrydata");
var text=data[0].getElementsByTagName("text");
var tdata=text[0].firstChild.nodeValue;
var TN_content="http://www.www.www" +tdata+"?OpenElement" ;

//Create img node and set image
var newref=document.createElement("img");
newref.setAttribute("src",TN_content);
newref.setAttribute("border",0);
ref.appendChild(newref);
0
Comment
Question by:questfar
  • 2
  • 2
  • 2
6 Comments
 
LVL 15

Expert Comment

by:mshogren
ID: 16670604
Try this:

// get the href data from the XML DOM
var data=entry[m].getElementsByTagName("entrydata");
var text=data[1].getElementsByTagName("text");
var tdata=text[0].firstChild.nodeValue;

//create a node and set href  
var ref = document.createElement("a");
ref.setAttribute("href",tdata);
img.insertBefore(ref);

var sp = document.createTextNode("            ");
img.insertBefore(sp);

//get the image data from the XML DOM
var data=entry[m].getElementsByTagName("entrydata");
var text=data[0].getElementsByTagName("text");
var tdata=text[0].firstChild.nodeValue;
var TN_content="http://www.www.www" +tdata+"?OpenElement" ;

//Create img node and set image
var newref=document.createElement("img");
newref.setAttribute("src",TN_content);
newref.setAttribute("border",0);
ref.appendChild(newref);
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 16670921
If you actually want the non-breaking space character (so that line breaks don't occur on it), then you'll have to add the right character.  A space character isn't the same thing.  

var sp = document.createTextNode(" ");
img.insertBefore(sp);

The actual character code might be different, depending on the encoding.  For example:    in UTF-16 or 슠 in UTF-8


Regards,
Mike Sharp
0
 

Author Comment

by:questfar
ID: 16671770
Well neither worked exactly, although the space was closer. The space was added in between the images , although I could not get it to add a space before the each first image in each row, regardless of where I put the code. The character code, simply put the text (" ") instead of a space, but it did add the characters in front of each first image in each row.



0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 15

Accepted Solution

by:
mshogren earned 2000 total points
ID: 16671821
To add spacing you should consider using the margin and padding CSS properties of the elements rather than using a character.

For instance add this line to the code which creates the link.

ref.setAttribute("style", "margin: 20px");
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 16671840
mshogren makes a good point here...

Mike  
0
 

Author Comment

by:questfar
ID: 16671855
of course, CSS takes care of the rest, thanks for pointing in the right direction


Orlando
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question