简体   繁体   中英

Loading xml data to html using DOM & javascript

I am trying load various xml data to an html. Among other data i have the path of a background image. The xml loads ok but i am getting a white space that separates my path to the bg image (d_onkey). There is no space in the xml file. Any ideas where that comes from?

xml example

  <event id="event104">
    <img>images\donkey_fest.jpg</img>
    <title>test</title>
    <type>Cultural</type>
    <date>Friday 25/5/16</date>
    <time>19:30-01:30</time>
    <place>Stadium</place>
    <area>Limassol</area>
    <description>some text</description>
    <url>http://www.thevillagexpress.com/cyprusvillage/profile/209&amp;lang=gr</url>
  </event> 

html code

document.getElementById("event_banner").style.backgroundImage = "url("+
x[i].getElementsByTagName("img")[0].childNodes[0].nodeValue + ")" ;

html outcome

<div style="background-image: url(&quot;images\d onkey_fest.jpg&quot;);" class="event_banner" id="event_banner">
      </div>

Thank you.

Haven't tested this myself, but could it be that the \\ in your path is interpreted as an escape charachter?

Try replacing it with "images\\\\donkey_fest.jpg"

I found a way around by putting the "images\\" to javascript. Issue solved. Thank you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM